﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;

using System.IO;
using System.Net;
using System.Collections;
using System.Xml.Serialization;
using ZedGraph;
using Newtonsoft.Json;
using LitJson;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;

namespace weiqijiance
{
    public partial class TESTASM : Form
    {
        public mainform m_mainform;
        /// <summary>
        /// 结果变量
        /// </summary>
        public int iHC25;
        public int iNO25;
        public float fCO25;
        public float lamda25;

        public int iHC25LS;
        public int iNO25LS;
        public float fCO25LS;
        public float lamda25LS;

        public int iHC40;
        public int iNO40;
        public float fCO40;
        public float lamda40;

        public float fwendu;
        public float fshidu;
        public double fdaqiya;
        /// <summary>
        ///限值变量
        /// </summary>
        public int iHCXZ25;
        public int iNOXZ25;
        public float fCOXZ25;

        public int iHCXZ40;
        public int iNOXZ40;
        public float fCOXZ40;


        //25过程数据
        public int IsTenMCondition25;
        public int IsTenMCondition40;
        public bool b2540;
        public int count5025;
        public int count2540=0;
        int[] m_HCGCSJ25 = new int[200];
        float[] m_COGCSJ25 = new float[200];
        int[] m_NOGCSJ25 = new int[200];
        float[] m_CO2GCSJ25 = new float[200];
        float[] m_O2GCSJ25 = new float[200];
        float[] m_LAMDAGCSJ25 = new float[200];
        float[] m_SpeedGCSJ25 = new float[200];
        int[] m_TrunGCSJ25 = new int[200];
        float[] m_PWGCSJ25 = new float[200];
        double[] m_DFGCSJ25 = new double[200];
        double[] m_KHGCSJ25 = new double[200];
        string [] m_ProcessTime25=new string[200];
        float[] m_NLGCSJ25 = new float[200];
        float[] m_jcztGCSJ25 = new float[200];

        int[] m_HCGCSJ25xz = new int[200];
        float[] m_COGCSJ25xz = new float[200];
        int[] m_NOGCSJ25xz = new int[200];
        int[] m_NOGCSJ25xzxs = new int[200];


        float[] syouwen25 = new float[200];		//测试工况流量计温度每秒数据,单位：℃
        float[] swendu25 = new float[200];		//测试工况环境温度每秒数
        float[] sdaqiyi25 = new float[200];		//测试工况环境大气压力每秒数据,单位：kPa
        float[] sshidu25 = new float[200];

        float[] sglkqxs25 = new float[200];


        int[] m_HCGCSJ40 = new int[200];
        float[] m_COGCSJ40 = new float[200];
        int[] m_NOGCSJ40 = new int[200];
        float[] m_CO2GCSJ40 = new float[200];
        float[] m_O2GCSJC40 = new float[200];
        float[] m_LAMDAGCSJ40 = new float[200];
        float[] m_SpeedGCSJ40 = new float[200];
        int[] m_TrunGCSJ40 = new int[200];
        float[] m_PWGCSJ40 = new float[200];
        double[] m_DFGCSJ40 = new double[200];
        double[] m_KHGCSJ40 = new double[200];

        float[] syouwen40 = new float[200];		//测试工况流量计温度每秒数据,单位：℃
        float[] swendu40 = new float[200];		//测试工况环境温度每秒数
        float[] sdaqiyi40 = new float[200];		//测试工况环境大气压力每秒数据,单位：kPa
        float[] sshidu40 = new float[200];
        string[] m_ProcessTime40 = new string[200];
        float[] m_NLGCSJ40 = new float[200];
        float[] m_jcztGCSJ40 = new float[200];

        int[] m_HCGCSJ40xz = new int[200];
        float[] m_COGCSJ40xz = new float[200];
        int[] m_NOGCSJ40xz = new int[200];
        int[] m_NOGCSJ40xzxs = new int[200];

        //
        public string sxianshineirong;
        public int itime;//剩余时间
        public int itrun;//当前发动机转速
        public float m_fspeed;
        public bool bgood;
        public int icccs;//连续超出速度次数
        public int iljcccs;//累计超出次数

        public string szsqz;
        public string sASMzs;
        public int izbzl;

        public float fForce;
        public bool ASM_Start;
        public bool ASM_Stop;
        public bool ASM_End;

        public double fdjzs5025 = 0;//发动机转速
        public double fdjyw5025 = 0;//油温
        public double cs5025 = 0;//平均车速
        public double jzzgl5025 = 0;//功率
        public double fdjzs2540 = 0;
        public double fdjyw2540 = 0;
        public double cs2540 = 0;
        public double jzzgl2540 = 0;

        public Thread t1;
        public Thread t2;
        public Thread t3;
        public bool bdushu;
        public bool bfh = false;

        public bool ceshi = false;//测试fwj
        // /声明INI文件的写操作函数 WritePrivateProfileString()
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;



        public static string businessId;
        public int DETECT_ID = 0;
        public static string registCode;
        public static string timeStart;
        public static string timeEnd;
        public int inspectNum;

        public float m_fCO;
        public int m_iHC;
        public int m_iNO;
        public bool wqtl;//尾气调零
        public string sASMllgd;
        public string ssfyqyw;//是否要求油温检测
        public DateTime dtl;

        public double shuchu;


        public string scllx;

        public string sASMJGXZ;//是否进行结果修正
        public int iASMtdz;//ASM信号左通道
        public int iASMtdy;//ASM信号右通道
        public int iASMtdh;//ASM信号右通道
        public int iASMHWQ;//ASM到位红外

        public int iASMKZJSS;//ASM举升升
        public int iASMKZJSJ;//ASM举升降
        public int iASMSDtd;//车速信号接在那个通道

        //红外取反
        public bool[] bhongwaiqf = new bool[16] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };//红外是否取反
        //红外定位时间
        public int[] ihongwaidwsj = new int[16] { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };//红外定位时间单位毫秒


        public string[] scolorname;
        public TextBox[] m_tex;

        public string[] sBJname;
        public string[] sBJnamecolor;


        public float[] sudu = new float[10000];
        public float[] gl = new float[10000];
        public float[] f_sk = new float[10000];
        public int ileng;

        public string[] ssudu = new string[10000];
        public string[] sgl = new string[10000];
        public int itlsj;
       

        /// <summary>
        /// 
        /// OBD
        /// </summary>
        /// <param name="sbusinessId"></param>
        /// <param name="sregistCode"></param>
        string[] OBD_jqmkd = new string[1000];
        string[] OBD_fh = new string[1000];
        string[] OBD_qycgqxh = new string[1000];
        string[] OBD_glkqxs = new string[1000];
        string[] OBD_ymkd = new string[1000];
        string[] OBD_cs = new string[1000];
        string[] OBD_fdjzs = new string[1000];
        string[] OBD_jql = new string[1000];
        string[] OBD_jqyl = new string[1000];
        string[] OBD_scgl = new string[1000];
        string[] OBD_zyyl = new string[1000];
        string[] OBD_hyl = new string[1000];
        string[] OBD_no = new string[1000];
        string[] OBD_nsbsl = new string[1000];
        string[] OBD_pqwd = new string[1000];
        string[] OBD_klbjqyc = new string[1000];
        string[] OBD_egrkd = new string[1000];
        string[] OBD_rypsyl = new string[1000];
        string[] OBD_sjxl = new string[1000];
        public int iobd;

        public int ztasm=0;
        public string ASMType;

        public TESTASM(string sbusinessId, string sregistCode)
        {
            InitializeComponent();
            readjcxx();
            ileng = 0;
            shuchu = 800;
            dtl = DateTime.Now;
            iljcccs = 0;
            icccs = 0;
            fForce = 0;
            inspectNum = 1;
            m_fspeed = 0;
            businessId = sbusinessId;
            registCode = sregistCode;
           
            bianliangchushihua();
            sxianshineirong = "";
            readshezhiJC();
            aGauge13.Visible = true;
            aGauge1.Visible = false;
            
            ASM_Start = false;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            timer1.Enabled = true;
            x = this.Width;
            y = this.Height;
            setTag(this);


            scolorname = new string[3] {"提示框",
                                    "号牌号码",
                                    "时间提示"};
            m_tex = new TextBox[3] {xinxixianshi,
                                    hphm,
                                    time};

            sBJname = new string[1] { "曲线控件" };
            sBJnamecolor = new string[1] { "#AABBCC" };


            showTextBoxCOLOR();
            readshezhiBJ();

            WriteGraph(zg);
            gettongdao();
            bydhh = false;
            xinxixianshi.Text = string.Format("仪器调零中...");
            skinBut_ksjc.Enabled = false; 
           // showbut();

        }
        public void WriteGraph(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;
          //  myPane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f);
            myPane.Fill = new Fill(Color.White, System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[0]), 45.0f);
            // 设置图表的颜色填充，如果设置为FillType.None,则填充色和背景色相同
            myPane.Chart.Fill.Type = FillType.None;

            myPane.CurveList.Clear();

            myPane.Title.Text = string.Format("过程曲线");

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "过程数据";



            zgc.AxisChange();
            zgc.Invalidate();
        }
        public string shphm = "";
        public string shpzl = "";
        public string srllx = "";
        /// <summary>
        /// 变量初始化
        /// </summary>
        public void bianliangchushihua()
        {
            iHC25 = 0;
            iNO25 = 0;
            fCO25 = 0;
            lamda25 = 0;
            iHC40 = 0;
            iNO40 = 0;
            fCO40 = 0;
            lamda40 = 0;

            iHCXZ25 = 0;
            iNOXZ25 = 0;
            fCOXZ25 = 0;
            iHCXZ40 = 0;
            iNOXZ40 = 0;
            fCOXZ40 = 0;
           
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            hphm.Text = ReadValue("设置", "车牌号码");
            scllx = ReadValue("设置", "车辆类型");
            shphm = ReadValue("设置", "车牌号码");
            shpzl = ReadValue("设置", "号牌种类");
            srllx = ReadValue("设置", "燃料类型");
            int.TryParse(ReadValue("设置", "基准质量"), out izbzl);
            mainform.hphm = ReadValue("设置", "车牌号码");
            mainform.hpzl = ReadValue("设置", "号牌种类");
        }
        //string CO2sz = "";
        public void readshezhiJC()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测要求设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            sASMzs = "是";// ReadValue("设置", "ASM要求速度");
            sASMllgd = "是";// ReadValue("设置", "ASM流量过低要求");
            sASMJGXZ = "是";//sASMJGXZ = ReadValue("设置", "ASM结果修正");
            ssfyqyw = ReadValue("设置", "油温检测要求");
            int.TryParse(ReadValue("设置", "ASM调零时间/秒"), out itlsj);
            //CO2sz = ReadValue("设置", "柴油车CO2");
            if (itlsj < 10)
            {
                itlsj = 35;
            }
        }
        public void readjcxx()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测参数设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            int.TryParse(ReadValue("设置", "ASM调零时间/秒"), out itlsj);
            if (itlsj < 10)
            {
                itlsj = 35;
            }
        }
        public void showTextBoxCOLOR()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\ASM工况颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            for (int i = 0; i < 3; i++)
            {
                textbox_xs(m_tex[i], System.Drawing.ColorTranslator.FromHtml(ReadValue("ASM工况颜色配置", scolorname[i])));
            }
        }
        public void readshezhiBJ()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\ASM工况颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 1; i++)
            {
                sBJnamecolor[i] = ReadValue("ASM工况颜色配置", sBJname[i]);

            }
        }
        public void textbox_xs(TextBox tex, Color cColor)//textbox显示风格
        {

            tex.ForeColor = cColor;

        }

       
        public void buttton_pic(Button but, string sfile)//按钮控件显示风格
        {
            but.BackgroundImage = Image.FromFile(string.Format(@"{0}", sfile));
            but.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            but.ImageAlign = ContentAlignment.TopLeft;
            but.TextAlign = ContentAlignment.TopRight;
            but.ForeColor = Color.Red;
            but.Font = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); ;

        }


        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion


        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件
        public void gettongdao()
        {

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            for (int i = 0; i < 10; i++)
            {
                string sgetname = ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname.Contains("测功力左"))
                {
                    iASMtdz = i;
                }

                if (sgetname.Contains("测功力右"))
                {
                    iASMtdy = i;
                }

                if (sgetname.Contains("测功力后"))
                {
                    iASMtdh = i;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                string smaichong = ReadValue("通道设置", string.Format(@"速度{0}", i + 1));
                if (smaichong.Contains("速度"))
                {
                    iASMSDtd = i;
                }

            }

            for (int i = 0; i < 16; i++)
            {
                string shongwai = ReadValue("通道设置", string.Format(@"红外{0}", i + 1));
                if (shongwai.Contains("测功机到位"))
                {
                    iASMHWQ = i;
                }


                shongwai = ReadValue("通道设置", string.Format(@"红外定位时间{0}", i + 1));
                int.TryParse(shongwai, out ihongwaidwsj[i]);


                shongwai = ReadValue("通道设置", string.Format(@"红外是否取反{0}", i + 1));
                if (shongwai.Contains("是"))
                {
                    bhongwaiqf[i] = true;
                }
                else
                {
                    bhongwaiqf[i] = false;
                }
            }
            ///控制
            for (int i = 0; i < 8; i++)
            {

                string shongwai = ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("测功举升升"))
                {
                    iASMKZJSS = i;
                }
                if (shongwai.Contains("测功举升降"))
                {
                    iASMKZJSJ = i;
                }
            }
        }


        private delegate void FlushClient();//代理
        private void xianshixinxi()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xinxixianshi.Text = string.Format(@"{0}", sxianshineirong);
            }
        }
        private void xianshitime()
        {
            if (this.time.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitime);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                if (itime == 0)
                {
                    this.time.Text = string.Format(@"-");
                }
                else
                {
                    this.time.Text = string.Format(@"剩{0}s", itime);
                }

            }
        }
        private void xianshiyibiao()
        {
            if (this.aGauge13.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiyibiao);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {

                this.aGauge13.Value = m_fspeed;
                this.aGauge13.CapText = "30.3";
                
            }
        }
        private void xianshiyibiao25xs()
        {
            if (this.aGauge13.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiyibiao25xs);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {

                this.aGauge13.Visible = false;

            }
        }
        private void xianshiyibiao40()
        {
            if (this.aGauge1.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiyibiao40);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {

                this.aGauge1.Value = m_fspeed;
            }
        }
        private void xianshiyibiao40xs()
        {
            if (this.aGauge1.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiyibiao40xs);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {

                this.aGauge1.Visible = true;
            }
        }

       
       
        protected void thisclose()
        {

            this.Invoke(new Action(this.Close));  //使用委托关闭该窗体
        }
        public void Thread1()
        {
            StratTest();

        }
        public void Thread2()
        {
           // for (; ; )
            DateTime ddatagcsj = DateTime.Now;

            while (bdushu)
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);

                xianshiyibiao();
                if (b2540)
                {
                    xianshiyibiao40();
                }
                else
                {
                    xianshiyibiao();
                }
                if (m_mainform.DateDiff(DateTime.Now, ddatagcsj) > 500)
                {
                    m_mainform.objfqy.SendDeviceCmd(3);
                    //if (m_mainform.sfqycj.Contains("鸣泉50A"))
                    //{
                    //    m_mainform.SendDeviceCmdGas(0x60, 0x9B);//  发送读取命令  
                    //}
                    //else
                    //{
                    //    m_mainform.SendDeviceCmdGas(0xA3, 0x58);//  发送读取命令 //WWT
                    //}
                    ddatagcsj = DateTime.Now;

                }
                xianshicojiaco2();
                xianshisp();
                Thread.Sleep(200);


                //xianshiNO();
                //xianshiHC();
                //xianshiCO();
            }
           

        }
        public DateTime sendDate2;
        //model.ASM.ASMgcsjZM objasmgcsjzm = new model.ASM.ASMgcsjZM();
        int igcsjds = 1;
        model.ASM.ASMobdgcsj objasmobds = new model.ASM.ASMobdgcsj();
        public void Thread3()
        {
            //OBD过程数据 
            int icountobdds = 0;
            //if (!m_mainform.sconnetname.Contains("安车") && !m_mainform.sconnetname.Contains("智慧"))
            {
                while (true)
                {
                    DateTime dtimeobddq = DateTime.Now;
                    if (icountobdds > 0 && dtimeobddq.ToString("yyyy-MM-dd HH:mm:ss") == objasmobds.obdjcsj[icountobdds - 1])
                    {
                        icountobdds--;
                    }
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                    }
                    objasmobds.ObdAirPressure[icountobdds] = m_mainform.OBD_jqyl.Length < 1 ? "0" : m_mainform.OBD_jqyl;
                    objasmobds.ObdAirInput[icountobdds] = m_mainform.OBD_jql.Length < 1 ? "0" : m_mainform.OBD_jql;
                    objasmobds.ObdRPM[icountobdds] = m_mainform.OBD_fdjzs.Length < 1 ? "0" : m_mainform.OBD_fdjzs;
                    objasmobds.ObdSpeed[icountobdds] = m_mainform.OBD_cs.Length < 1 ? "0" : m_mainform.OBD_cs;
                    objasmobds.ObdExcessAirFactor[icountobdds] = m_mainform.OBD_glkqxs.Length < 1 ? "0" : m_mainform.OBD_glkqxs;
                    objasmobds.ObdPreOxygen[icountobdds] = m_mainform.OBD_qycgqxh.Length < 1 ? "0" : m_mainform.OBD_qycgqxh;
                    objasmobds.ObdCLV[icountobdds] = m_mainform.OBD_fh.Length < 1 ? "0" : m_mainform.OBD_fh;
                    objasmobds.ObdThrottle[icountobdds] = m_mainform.OBD_jqmkd.Length < 1 ? "0" : m_mainform.OBD_jqmkd;
                    objasmobds.ObdPower[icountobdds] = m_mainform.OBD_scgl.Length < 1 ? "0" : m_mainform.OBD_scgl;
                    objasmobds.obdjcsj[icountobdds] = dtimeobddq.ToString("yyyy-MM-dd HH:mm:ss");
                    icountobdds++;
                    //if (bgcsj)
                    //{
                    //    break;
                    //}
                    Thread.Sleep(500);
                    if (m_mainform.DateDiff(DateTime.Now, sendDate2) > 1500 && m_mainform.sconnetname.Contains("安车") && byw)
                    {
                        sendDate2 = DateTime.Now;
                        //if (m_mainform.sconnetname.Contains("安车") && byw)
                        {

                            fywrg = float.Parse((fywrg + m_mainform.getRandom(1, 5) * 0.05f).ToString("0.00"));

                            if (fywrg > 110)
                            {
                                fywrg = float.Parse((110 + m_mainform.getRandom(1, 5) * 0.05f).ToString("0.00"));
                            }
                        }
                    }
                    Thread.Sleep(500);
                }
            }

        }

        public int ijcsj = 0;

        public model.ASM.ASMgcsj objasmgcsj;
        public model.ASM.ASMsj objasmsj;
        public string  yeid;
        public void StratTest()
        {
            //wwt20200917 异步上传过程数据
            taskgcsj = new Task(() => { });// = new Task();
            //taskobd= new Task(() => { });// = new Task();
            taskgcsj.Start();

            bfh = false;
            m_mainform.objbass.SendMessage("03", "开始检测");
            m_mainform.objbass.XXTZ("03");//中科开始
            iobd = 0;
            //
            yeid = m_mainform.objbass.getobdid(shphm);
            //
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\联网车辆ASM限值.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            iHCXZ25 = (int)m_mainform.HCEL5025;
            fCOXZ25 = m_mainform.COEL5025;
            iNOXZ25 = (int)m_mainform.NOEL5025;

            iHCXZ40 = (int)m_mainform.HCEL2540;
            fCOXZ40 = m_mainform.COEL2540;
            iNOXZ40 = (int)m_mainform.NOEL2540;

            bgood = true;
            b2540 = false;
            ASM_Start = true;
            ASM_Stop = false;
            IsTenMCondition25 = 1;
            IsTenMCondition40 = 1;
            m_mainform.DAC.PutVol(0);
            Thread.Sleep(2500);
            m_mainform.DAC.Lift(false);
            timeStart = DateTime.Now.ToLocalTime().ToString();
            m_mainform.DAC.tiaoling(1);
            //录像开始
            bool bsfjcwc = false;
            DETECT_ID = 0;
            if (m_mainform.IsInt(businessId))
            {
                int.TryParse(businessId, out DETECT_ID);
            }

            int ics = 1;
            if (srllx.Contains("3"))
            {
                ics = 2;
            }
            objasmsj.rllx = srllx;
            try
            {
                for (int i = 0; i < ics; i++)
                {
                    if (srllx.Contains("3"))//wwt20190611
                    {
                        if (i == 0)
                        {
                            sxianshineirong = "两用燃油，现在用单一汽油检测";
                            xianshixinxi();
                            Thread.Sleep(2000);
                        }
                        else
                        {
                            ztasm = 1;
                            sxianshineirong = "两用燃油，现在用单一气体检测";
                            xianshixinxi();
                            Thread.Sleep(2000);
                        }
                    }

                    bsfjcwc = StartGuoBiao5025();
                    // 保存过程数据到本地数据库
                    if (bsfjcwc)
                    {
                        // 保存过程数据到本地数据库
                        baocunGCSJ_ASM(businessId, m_mainform.testtimes);
                        baocunGCSJ_OBD(businessId);
                        if (m_mainform.sconnetname.Contains("yunjingjiu"))
                        {
                            bfh = uploadasmjcjg(businessId,i);
                        }
                        else
                        {
                            bfh = uploadasmjcjg(businessId, i);
                        }
                    }
                }
              

                //t3.Abort();
                //t3.DisableComObjectEagerCleanup();

                itime = 0;
                xianshitime();

                m_mainform.DAC.PutVol(0);
                m_mainform.objfqy.bfqyco2 = false;
                Thread.Sleep(1500);
                m_mainform.objfqy.SendDeviceCmd(2);//停止测量
                Thread.Sleep(1500);
                m_mainform.objfqy.SendDeviceCmd(4);//反吹

                if (bsfjcwc)
                {
                    sxianshineirong = string.Format("正在上传数据，请稍等");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("正在上传数据");
                        string sxiahang = string.Format("请稍等");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    while (true)
                    {
                        if (TaskStatus.RanToCompletion == taskgcsj.Status)
                        {
                            break;
                        }
                        Thread.Sleep(100);
                    }
                }
                bjiancestart = false;

                m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaoqian, "wqq");
                m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaohou, "wqh");
                m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaozhong, "wqqj");

                if (srllx.Contains("3"))//长沙智慧使用，其他厂家没有
                {
                    m_mainform.objbass.GetPIC("121");//稳态工况5025第一秒拍照点前照
                    m_mainform.objbass.GetPIC("122");//稳态工况5025最后一秒拍照点前照
                    m_mainform.objbass.GetPIC("123");//稳态工况2540第一秒拍照点前照
                    m_mainform.objbass.GetPIC("124");//稳态工况2540最后一秒拍照点前照
                    m_mainform.objbass.GetPIC("221");//稳态工况5025第一秒拍照点后照
                    m_mainform.objbass.GetPIC("222");//稳态工况5025最后一秒拍照点后照
                    m_mainform.objbass.GetPIC("223");//稳态工况2540第一秒拍照点后照
                    m_mainform.objbass.GetPIC("224");//稳态工况2540最后一秒拍照点后照
                    m_mainform.objbass.GetPic("1221");//稳态工况5025第一秒拍照点前照
                    m_mainform.objbass.GetPic("1222");//稳态工况5025最后一秒拍照点前照
                    m_mainform.objbass.GetPic("1223");//稳态工况2540第一秒拍照点前照
                    m_mainform.objbass.GetPic("1224");//稳态工况2540最后一秒拍照点前照
                    m_mainform.objbass.GetPic("2221");//稳态工况5025第一秒拍照点后照
                    m_mainform.objbass.GetPic("2222");//稳态工况5025最后一秒拍照点后照
                    m_mainform.objbass.GetPic("2223");//稳态工况2540第一秒拍照点后照
                    m_mainform.objbass.GetPic("2224");//稳态工况2540最后一秒拍照点后照
                }
                else
                {
                    m_mainform.objbass.GetPIC("121");//稳态工况5025第一秒拍照点前照
                    m_mainform.objbass.GetPIC("122");//稳态工况5025最后一秒拍照点前照
                    m_mainform.objbass.GetPIC("123");//稳态工况2540第一秒拍照点前照
                    m_mainform.objbass.GetPIC("124");//稳态工况2540最后一秒拍照点前照
                    m_mainform.objbass.GetPIC("221");//稳态工况5025第一秒拍照点后照
                    m_mainform.objbass.GetPIC("222");//稳态工况5025最后一秒拍照点后照
                    m_mainform.objbass.GetPIC("223");//稳态工况2540第一秒拍照点后照
                    m_mainform.objbass.GetPIC("224");//稳态工况2540最后一秒拍照点后照
                }
                m_mainform.objbass.LuXiang("01", "http://192.168.3.68:8083/wjzp/cjpt_1598425587359.mp4");
                m_mainform.objbass.LuXiang("02", "http://192.168.3.68:8083/wjzp/cjpt_1598425587359.mp4");
                m_mainform.objbass.LuXiang("03", "http://192.168.3.68:8083/wjzp/cjpt_1598425587359.mp4");
                //上传结束信息
                if (bfh)
                {
                    m_mainform.objbass.XXTZ("05");//中科结束
                    m_mainform.insertjcwc(businessId);
                    m_mainform.objbass.stop(businessId, bgood ? "1" : "0");
                } 

                sxianshineirong = string.Format("检测完成，请减速");
                xianshixinxi();
                {
                    string sshanghang = string.Format("检测完成");
                    string sxiahang = string.Format("请减速");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                while (true)
                {
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);

                    xianshiyibiao();
                    if (m_fspeed < 1)
                    {
                        break;
                    }
                    Thread.Sleep(500);
                }

                bdushu = false;
                m_mainform.DAC.PutVol(0);
                Thread.Sleep(1500);
                m_mainform.DAC.Lift(true);
                Thread.Sleep(3000);
                thisclose();
                //this.Close();

            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("ASM稳态工况", ex.Message.ToString());
            }
				           
        }
        联网通信协议.安车model.GC011 gc011;
        public void aclwsj()
        {
            联网通信协议.安车model.GC002 gc002 = new 联网通信协议.安车model.GC002();
            联网通信协议.安车model.JC002 jc002 = new 联网通信协议.安车model.JC002();

            string cysx = "";
            string hcclz = "";
            string noclz = "";
            string cs = "";
            string zs = "";
            string coclz = "";
            string co2clz = "";
            string o2clz = "";
            string xsxzxs = "";
            string sdxzxs = "";
            string jsgl = "";
            string zsgl = "";
            string jzgl = "";
            string hjwd = "";
            string dqyl = "";
            string xdsd = "";
            string yw = "";
            string sjxl = "";
            string nl = "";
            string scfz = "";
            string jczt = "";
            string glkqxs = "";
            string noclzwxz = "";
            string hcclzxzh = "";
            string noclzxzh = "";
            string coclzxzh = "";
            string jcsj = "";
            string gksj = "";

            for (int i = 0; i < count5025 + 1; i++)
            {
                if (i == 0)
                {
                    cysx = string.Format(@"{0}", i + 1);
                    cs = string.Format(@"{0}", m_SpeedGCSJ25[i].ToString("0.00"));
                    zs = string.Format(@"{0}", m_TrunGCSJ25[i]);
                    co2clz = string.Format(@"{0}", m_CO2GCSJ25[i]);
                    o2clz = string.Format(@"{0}", m_O2GCSJ25[i]);

                    xsxzxs = string.Format(@"{0}", m_DFGCSJ25[i].ToString("0.000")); ;
                    sdxzxs = string.Format(@"{0}", m_KHGCSJ25[i].ToString("0.000"));
                    jsgl = string.Format(@"{0}", 0.5f);
                    zsgl = string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    jzgl = string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    hjwd = string.Format(@"{0}", swendu25[i]);
                    dqyl = string.Format(@"{0}", sdaqiyi25[i]);
                    xdsd = string.Format(@"{0}", sshidu25[i]);
                    yw = string.Format(@"{0}", syouwen25[i]);

                    sjxl = string.Format(@"{0}", m_ProcessTime25[i].Length < 1 ? m_ProcessTime25[1] : m_ProcessTime25[i]);
                    nl = string.Format(@"{0}", m_NLGCSJ25[i]);
                    scfz = string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    jczt = string.Format(@"{0}", m_jcztGCSJ25[i]);

                    hcclz = string.Format(@"{0}", m_HCGCSJ25[i]);
                    noclz = string.Format(@"{0}", m_NOGCSJ25[i]);
                    coclz = string.Format(@"{0}", m_COGCSJ25[i]);

                    noclzwxz = string.Format(@"{0}", m_NOGCSJ25xzxs[i]);
                    hcclzxzh = string.Format(@"{0}", m_HCGCSJ25xz[i]);
                    noclzxzh = string.Format(@"{0}", m_NOGCSJ25xz[i]);
                    coclzxzh = string.Format(@"{0}", m_COGCSJ25xz[i]);
                    glkqxs = string.Format(@"{0}", m_LAMDAGCSJ25[i]);
                }
                else
                {
                    cysx = cysx + "," + string.Format(@"{0}", i + 1);
                    hcclz = hcclz + "," + string.Format(@"{0}", m_HCGCSJ25[i]);
                    noclz = noclz + "," + string.Format(@"{0}", m_NOGCSJ25[i]);
                    cs = cs + "," + string.Format(@"{0}", m_SpeedGCSJ25[i].ToString("0.00"));
                    zs = zs + "," + string.Format(@"{0}", m_TrunGCSJ25[i]);
                    coclz = coclz + "," + string.Format(@"{0}", m_COGCSJ25[i]);
                    co2clz = co2clz + "," + string.Format(@"{0}", m_CO2GCSJ25[i]);
                    o2clz = o2clz + "," + string.Format(@"{0}", m_O2GCSJ25[i]);

                    xsxzxs = xsxzxs + "," + string.Format(@"{0}", m_DFGCSJ25[i].ToString("0.000")); ;
                    sdxzxs = sdxzxs + "," + string.Format(@"{0}", m_KHGCSJ25[i].ToString("0.000"));
                    jsgl = jsgl + "," + string.Format(@"{0}", 0.5f);
                    zsgl = zsgl + "," + string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    jzgl = jzgl + "," + string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    hjwd = hjwd + "," + string.Format(@"{0}", swendu25[i]);
                    dqyl = dqyl + "," + string.Format(@"{0}", sdaqiyi25[i]);
                    xdsd = xdsd + "," + string.Format(@"{0}", sshidu25[i]);
                    yw = yw + "," + string.Format(@"{0}", syouwen25[i]);
                    glkqxs = glkqxs + "," + string.Format(@"{0}", m_LAMDAGCSJ25[i]);

                    sjxl = sjxl + "," + string.Format(@"{0}", m_ProcessTime25[i]);
                    nl = nl + "," + string.Format(@"{0}", m_NLGCSJ25[i]);
                    scfz = scfz + "," + string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    if (i > count5025 - 10)
                    {
                        jczt = jczt + "," + "2";
                    }
                    else
                    {
                        jczt = jczt + "," + "1";
                    }
                    noclzwxz = noclzwxz + "," + string.Format(@"{0}", m_NOGCSJ25xzxs[i]);
                    hcclzxzh = hcclzxzh + "," + string.Format(@"{0}", m_HCGCSJ25xz[i]);
                    noclzxzh = noclzxzh + "," + string.Format(@"{0}", m_NOGCSJ25xz[i]);
                    coclzxzh = coclzxzh + "," + string.Format(@"{0}", m_COGCSJ25xz[i]);
                }
            }
            //保存曲线数据
            if (b2540)
            {
                for (int i = 0; i < count2540 + 1; i++)
                {
                    cysx = cysx + "," + string.Format(@"{0}", 90 + i + 1);
                    hcclz = hcclz + "," + string.Format(@"{0}", m_HCGCSJ40[i]);
                    noclz = noclz + "," + string.Format(@"{0}", m_NOGCSJ40[i]);
                    cs = cs + "," + string.Format(@"{0}", m_SpeedGCSJ40[i].ToString("0.00"));
                    zs = zs + "," + string.Format(@"{0}", m_TrunGCSJ40[i]);
                    coclz = coclz + "," + string.Format(@"{0}", m_COGCSJ40[i]);
                    co2clz = co2clz + "," + string.Format(@"{0}", m_CO2GCSJ40[i]);
                    o2clz = o2clz + "," + string.Format(@"{0}", m_O2GCSJC40[i]);

                    xsxzxs = xsxzxs + "," + string.Format(@"{0}", m_DFGCSJ40[i].ToString("0.000")); ;
                    sdxzxs = sdxzxs + "," + string.Format(@"{0}", m_KHGCSJ40[i].ToString("0.000"));
                    jsgl = jsgl + "," + string.Format(@"{0}", 0.5f);
                    zsgl = zsgl + "," + string.Format(@"{0}", m_PWGCSJ40[i].ToString("0.00"));
                    jzgl = jzgl + "," + string.Format(@"{0}", m_PWGCSJ40[i].ToString("0.00"));
                    hjwd = hjwd + "," + string.Format(@"{0}", swendu40[i]);
                    dqyl = dqyl + "," + string.Format(@"{0}", sdaqiyi40[i]);
                    xdsd = xdsd + "," + string.Format(@"{0}", sshidu40[i]);
                    yw = yw + "," + string.Format(@"{0}", syouwen40[i]);
                    glkqxs = glkqxs + "," + string.Format(@"{0}", m_LAMDAGCSJ40[i]);

                    sjxl = sjxl + "," + string.Format(@"{0}", m_ProcessTime40[i]);
                    nl = nl + "," + string.Format(@"{0}", m_NLGCSJ40[i]);
                    scfz = scfz + "," + string.Format(@"{0}", m_PWGCSJ40[i].ToString("0.00"));
                    if (i > count2540 - 10)
                    {
                        jczt = jczt + "," + "4";
                    }
                    else
                    {
                        jczt = jczt + "," + "3";
                    }

                    noclzwxz = noclzwxz + "," + string.Format(@"{0}", m_NOGCSJ40xzxs[i]);
                    hcclzxzh = hcclzxzh + "," + string.Format(@"{0}", m_HCGCSJ40xz[i]);
                    noclzxzh = noclzxzh + "," + string.Format(@"{0}", m_NOGCSJ40xz[i]);
                    coclzxzh = coclzxzh + "," + string.Format(@"{0}", m_COGCSJ40xz[i]);

                }
            }

            //上传数据
            string sHC40 = "";
            string sHCEL2540 = "";
            string HC40pd = "";
            string sCO40 = "";
            string sCOEL2540 = "";
            string CO40pd = "";
            string sNO40 = "";
            string sNOEL2540 = "";
            string NO40pd = "";
            string Lamda40 = "";
            if (b2540)
            {
                sHC40 = string.Format("{0}", iHC40);
                sHCEL2540 = string.Format("{0}", m_mainform.HCEL2540);
                HC40pd = Convert.ToString(iHC40 > m_mainform.HCEL2540 ? 0 : 1);


                sCO40 = fCO40.ToString("0.00");
                sCOEL2540 = string.Format("{0}", m_mainform.COEL2540);
                CO40pd = Convert.ToString(fCO40 > m_mainform.COEL2540 ? 0 : 1);

                if (lamda40 == 0)
                {
                    lamda40 = 1.03f;
                }

                sNO40 = string.Format("{0}", iNO40);
                sNOEL2540 = string.Format("{0}", m_mainform.NOEL2540.ToString("0"));
                NO40pd = Convert.ToString(iNO40 > m_mainform.NOEL2540 ? 0 : 1);
                Lamda40 = string.Format("{0}", lamda40);
            }
            int ids = count5025 + 1;
            if (count2540 > 1)
            {
                ids = 90 + count2540 + 1;
            }

            gc002.cyds = ids.ToString();
            gc002.cysx = cysx;
            gc002.hcclz = hcclz;
            gc002.noclz = noclz;
            gc002.cs = cs;
            gc002.zs = zs;
            gc002.coclz = coclz;
            gc002.co2clz = co2clz;
            gc002.o2clz = o2clz;
            gc002.xsxzxs = xsxzxs;
            gc002.sdxzxs = sdxzxs;
            gc002.jsgl = jsgl;
            gc002.zsgl = zsgl;
            gc002.jzgl = jzgl;
            gc002.hjwd = hjwd;
            gc002.dqyl = dqyl;
            gc002.xdsd = xdsd;
            gc002.yw = yw;
            gc002.sjxl = sjxl;
            gc002.nl = nl;
            gc002.scfz = scfz;
            gc002.glkqxs = glkqxs;
            gc002.jczt = jczt;

            gc002.glkqxs = glkqxs;
            gc002.noclzwxz = noclzwxz;
            gc002.hcclzxzh = hcclzxzh;
            gc002.noclzxzh = noclzxzh;
            gc002.coclzxzh = coclzxzh;
            gc002.jcsj = jcsj;
            gc002.gksj = gksj;

            obdsc();//发送OBD过程数据

            jc002.wd = fwendu.ToString("0.00");
            jc002.dqy = fdaqiya.ToString("0.00");
            jc002.xdsd = fshidu.ToString("0.00");
            jc002.lambda = Lamda40;
            jc002.hc5025limit = m_mainform.HCEL5025.ToString("0");
            jc002.hc5025 = (iHC25).ToString();
            jc002.hc5025judge = (iHC25 > m_mainform.HCEL5025 ? 0 : 1).ToString();
            jc002.co5025limit = m_mainform.COEL5025.ToString("0.0");
            jc002.co5025 = fCO25.ToString("0.00");
            jc002.co5025judge = (fCO25 > m_mainform.COEL5025 ? 0 : 1).ToString();
            jc002.no5025limit = m_mainform.NOEL5025.ToString("0");
            jc002.no5025 = (iNO25).ToString();
            jc002.no5025judge = (iNO25 > m_mainform.NOEL5025 ? 0 : 1).ToString();
            jc002.fdjzs5025 = m_TrunGCSJ25[0].ToString();
            jc002.fdjyw5025 = syouwen25[0].ToString();
            jc002.hc2540limit = sHCEL2540;
            jc002.hc2540 = sHC40;
            jc002.hc2540judge = HC40pd;
            jc002.co2540limit = sCOEL2540;//1
            jc002.co2540 = sCO40;  //2                                
            jc002.co2540judge = CO40pd;
            jc002.no2540limit = sNOEL2540;
            jc002.no2540 = sNO40;
            jc002.no2540judge = NO40pd;
            jc002.fdjzs2540 = m_TrunGCSJ40[0].ToString();
            jc002.fdjyw2540 = syouwen40[0].ToString();
            jc002.jzzgl5025 = m_PWGCSJ25[0].ToString("0.0");
            jc002.jzzgl2540 = m_PWGCSJ40[0].ToString("0.0");
            jc002.result = (bgood ? 1 : 0).ToString();

            //string neirong = m_mainform.objbass.uploadASM(gc002, gc011, jc002);
            //if (neirong.Trim().Length > 0)
            //{
            //    sxianshineirong = neirong;
            //    xianshixinxi();
            //    return;
            //}
        }
        public bool uploadasmjcjg(string businessId,int ics)
        {
            objasmsj.iHC25 = iHC25;
            objasmsj.iNO25 = iNO25;
            objasmsj.fCO25 = fCO25;
            objasmsj.lamda25 = lamda25;
            objasmsj.iHC40 = iHC40;
            objasmsj.iNO40 = iNO40;
            objasmsj.fCO40 = fCO40;
            objasmsj.lamda40 = lamda40;
            objasmsj.fwendu = fwendu;
            objasmsj.fshidu = fshidu;
            objasmsj.fdaqiya = fdaqiya;
            objasmsj.iHCXZ25 = iHCXZ25;
            objasmsj.iNOXZ25 = iNOXZ25;
            objasmsj.fCOXZ25 = fCOXZ25;
            objasmsj.iHCXZ40 = iHCXZ40;
            objasmsj.iNOXZ40 = iNOXZ40;
            objasmsj.fCOXZ40 = fCOXZ40;
            objasmsj.ASMType = ASMType;

            objasmsj.fdjzs5025 = fdjzs5025;//发动机转速
            objasmsj.fdjyw5025 = fdjyw5025;//油温
            objasmsj.cs5025 = cs5025;//平均车速
            objasmsj.jzzgl5025 = jzzgl5025;//功率
            objasmsj.fdjzs2540 = fdjzs2540;
            objasmsj.fdjyw2540 = fdjyw2540;
            objasmsj.cs2540 = cs2540;
            objasmsj.jzzgl2540 = jzzgl2540;


            objasmsj.b2540 = b2540;
            objasmsj.result = (bgood ? 1 : 0).ToString();//新增

            objasmgcsj.count5025 = count5025;
            objasmgcsj.count2540 = count2540;
            objasmgcsj.m_HCGCSJ25 = m_HCGCSJ25;
            objasmgcsj.m_COGCSJ25 = m_COGCSJ25;
            objasmgcsj.m_NOGCSJ25 = m_NOGCSJ25;
            objasmgcsj.m_CO2GCSJ25 = m_CO2GCSJ25;
            objasmgcsj.m_O2GCSJ25 = m_O2GCSJ25;
            objasmgcsj.m_LAMDAGCSJ25 = m_LAMDAGCSJ25;
            objasmgcsj.m_SpeedGCSJ25 = m_SpeedGCSJ25;
            objasmgcsj.m_TrunGCSJ25 = m_TrunGCSJ25;
            objasmgcsj.m_PWGCSJ25 = m_PWGCSJ25;
            objasmgcsj.m_DFGCSJ25 = m_DFGCSJ25;
            objasmgcsj.m_KHGCSJ25 = m_KHGCSJ25;
            objasmgcsj.m_ProcessTime25 = m_ProcessTime25;
            objasmgcsj.m_NLGCSJ25 = m_NLGCSJ25;
            objasmgcsj.m_jcztGCSJ25 = m_jcztGCSJ25;
            objasmgcsj.m_HCGCSJ25xz = m_HCGCSJ25xz;
            objasmgcsj.m_COGCSJ25xz = m_COGCSJ25xz;
            objasmgcsj.m_NOGCSJ25xz = m_NOGCSJ25xz;
            objasmgcsj.m_NOGCSJ25xzxs = m_NOGCSJ25xzxs;
            objasmgcsj.syouwen25 = syouwen25;
            objasmgcsj.swendu25 = swendu25;
            objasmgcsj.sdaqiyi25 = sdaqiyi25;
            objasmgcsj.sshidu25 = sshidu25;
            objasmgcsj.sglkqxs25 = sglkqxs25;

            objasmgcsj.m_HCGCSJ40 = m_HCGCSJ40;
            objasmgcsj.m_COGCSJ40 = m_COGCSJ40;
            objasmgcsj.m_NOGCSJ40 = m_NOGCSJ40;
            objasmgcsj.m_CO2GCSJ40 = m_CO2GCSJ40;
            objasmgcsj.m_O2GCSJC40 = m_O2GCSJC40;
            objasmgcsj.m_LAMDAGCSJ40 = m_LAMDAGCSJ40;
            objasmgcsj.m_SpeedGCSJ40 = m_SpeedGCSJ40;
            objasmgcsj.m_TrunGCSJ40 = m_TrunGCSJ40;
            objasmgcsj.m_PWGCSJ40 = m_PWGCSJ40;
            objasmgcsj.m_DFGCSJ40 = m_DFGCSJ40;
            objasmgcsj.m_KHGCSJ40 = m_KHGCSJ40;
            objasmgcsj.syouwen40 = syouwen40;
            objasmgcsj.swendu40 = swendu40;
            objasmgcsj.sdaqiyi40 = sdaqiyi40;
            objasmgcsj.sshidu40 = sshidu40;
            objasmgcsj.m_ProcessTime40 = m_ProcessTime40;
            objasmgcsj.m_NLGCSJ40 = m_NLGCSJ40;
            objasmgcsj.m_jcztGCSJ40 = m_jcztGCSJ40;
            objasmgcsj.m_HCGCSJ40xz = m_HCGCSJ40xz;
            objasmgcsj.m_COGCSJ40xz = m_COGCSJ40xz;
            objasmgcsj.m_NOGCSJ40xz = m_NOGCSJ40xz;
            objasmgcsj.m_NOGCSJ40xzxs = m_NOGCSJ40xzxs;
            objasmgcsj.IsTenMCondition25 = IsTenMCondition25;
            objasmgcsj.IsTenMCondition40 = IsTenMCondition40;


            //OBD过程数据 
            model.ASM.ASMobdgcsj objasmobd = new model.ASM.ASMobdgcsj();
            objasmobd.ObdAirPressure = OBD_jqyl;
            objasmobd.ObdAirInput = OBD_jql;
            objasmobd.ObdRPM = OBD_fdjzs;
            objasmobd.ObdSpeed = OBD_cs;
            objasmobd.ObdExcessAirFactor = OBD_glkqxs;
            objasmobd.ObdPreOxygen = OBD_qycgqxh;
            objasmobd.ObdCLV = OBD_fh;
            objasmobd.ObdThrottle = OBD_jqmkd;
            objasmobd.Obdsjxl = OBD_sjxl;//新增
            objasmobd.Obdiobd = iobd;//新增
            objasmobd.Obdymkd = OBD_ymkd;//新增
            objasmobd.Obdscgl = OBD_scgl;//新增
            objasmobd.Obdzyyl = OBD_zyyl;//新增
            objasmobd.Obdhyl = OBD_hyl;//新增
            objasmobd.Obdno = OBD_no;//新增
            objasmobd.Obdnsbsl = OBD_nsbsl;//新增
            objasmobd.Obdpqwd = OBD_pqwd;//新增
            objasmobd.Obdklbjqyc = OBD_klbjqyc;//新增
            objasmobd.Obdegrkd = OBD_egrkd;//新增
            objasmobd.Obdrypsyl = OBD_rypsyl;//新增

            objasmobd.ObdPower =OBD_scgl;

            string message = m_mainform.objbass.sjuploadASM(businessId, objasmsj, objasmgcsj, objasmobd,ics);
            if (!message.Contains("1"))
            {
                sxianshineirong = message;
                xianshixinxi();
                Thread.Sleep(3000);
                return false;
            }
            return true;
        }

        int igcds = 1;

        Task taskgcsj;// = new Task();
        DateTime dtgcsj;
        int igcsjcount = 0;
        public bool StartGuoBiao5025()//国标
        {

            DateTime dcomfh = DateTime.Now;
            float Ra = 0;
            double Pd = 0;
            double Pb = 0;
            sxianshineirong = "ASM工况法";
            xianshixinxi();
            string sshanghang = "ASM工况法";
            string sxiahang = "开始检测";
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            float fjiazaiPower = (float)izbzl / 148f;//加载的功率

            if (scllx.Contains("重"))
            {
                if (fjiazaiPower > 25)
                {
                    fjiazaiPower = 25;
                }
            }
            else
            {
                if (fjiazaiPower < 1 || fjiazaiPower > 20)
                {
                    fjiazaiPower = 10;//测试使用
                }

            }
            jzzgl5025 = fjiazaiPower;//功率
            //P5025-2=RM / 148
            //P2540-2=RM / 185
            //式中：RM—基准质量，kg；
            //P5025-2—滚筒直径为218mm±2mm的测功机ASM5025工况设定功率值，kW；
            //P2540-2—滚筒直径为218mm±2mm的测功机ASM2540工况设定功率值，kW。
            //对重型车，如果P5025-2或P2540-2的加载功率计算结果大于或等于25.0kW，均按25.0kW进行加载测试。

            float fForce25 = fjiazaiPower * 360f / 25f;

            //25过程数据
            for (int iqd = 0; iqd < 3; iqd++)
            {
                m_mainform.objfqy.SendDeviceCmd(1);//启动废气仪
                Thread.Sleep(1000);
            }
            //m_mainform.SendDeviceCmdGas(0x79, 0x82);//启动废气仪
            DateTime dstart = DateTime.Now;

            //m_mainform.gethuanjing();//读取数据库环境参数 

            Ra = fshidu;
            Pd = fdaqiya;



            ////////////////加速到25公里
            float fX = 0;
            double d = 4.644;//////汽油车d=4.644;压缩天然气--6.64,液化石油气--5.39
            double k;
            double H;
            H = 43.478 * Ra * Pd / (Pb - (Pd * Ra / 100));
            k = 1 / (1 - 0.0047 * (H - 75));
            sxianshineirong = "ASM5025检测开始加速到25km/h";
            xianshixinxi();

            sshanghang = "5025检测开始";
            sxiahang = "到25km/h";
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            if (m_mainform.objfqy.m_fWenDu > 22)
            {
                sxianshineirong = string.Format("请启动冷却风机");
                xianshixinxi();
                {
                    sshanghang = string.Format("请启动冷却风机");
                    sxiahang = string.Format("");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                Thread.Sleep(2000);
            }
            //t2.Start();
            //图片

            //if (ssfyqyw.Contains("是"))
            {

                while (true)
                {

                    Thread.Sleep(500);
                    sxianshineirong = string.Format("当前油温:{0}度不符合测试要求",byw ? fywrg : m_mainform.objfqy.m_fyw);
                    xianshixinxi();

                    sshanghang = string.Format("当前油温{0}度", byw ? fywrg : m_mainform.objfqy.m_fyw);
                    sxiahang = "不符合测试要求";
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    if ((byw ? fywrg : m_mainform.objfqy.m_fyw) > 80)
                    {
                        break;
                    }
                }
            }

            while (true)
            {

                Thread.Sleep(500);

                if (rbOBDZS.Checked)
                {
                    m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                    int ifdjzs = 0;
                    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                    itrun = ifdjzs;
                }
                else
                {
                    itrun = m_mainform.objzsy.m_iGasturn;
                }
                sxianshineirong = string.Format("{0}。请插入转速", itrun);
                xianshixinxi();
                sshanghang = string.Format("转速{0}", itrun);
                sxiahang = "请插入转速";
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                //if ((byw ? fywrg : m_mainform.objfqy.m_fyw) > 80)
                //{
                //    break;
                //}
                if (itrun > 500)
                {
                    break;
                }
            }
            while (true)//test
            {

                Thread.Sleep(500);
                sxianshineirong = string.Format("CO2+CO大于6 {0}", m_mainform.objfqy.m_fCo2 + m_mainform.objfqy.m_fCo);
                xianshixinxi();
                sshanghang = string.Format("{0}", m_mainform.objfqy.m_fCo2 + m_mainform.objfqy.m_fCo);
                sxiahang = "CO2+CO大于6 ";
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                if (bydhh)
                    break;
                if (m_mainform.objfqy.m_fCo2 + m_mainform.objfqy.m_fCo > 6)
                {
                    break;
                }
            }

            //
                dtgcsj = DateTime.Now;
            bool b5025gk = true;//所有检测污染物连续10秒的平均值经修正后均不大于标准规定的限值 true 否则为 false

            sxianshineirong = "检测准备中";
            xianshixinxi();

            sshanghang = string.Format("检测准备中");
            sxiahang = "检测准备中";
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            for (int jczb = 0; jczb < 5; jczb++)
            {
                if (rbOBDZS.Checked)
                {
                    m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                    int ifdjzs = 0;
                    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                    itrun = ifdjzs;
                }
                else
                {
                    itrun = m_mainform.objzsy.m_iGasturn;
                }
                if (itrun < 500 || itrun > 5000)
                {
                    sxianshineirong = "转速异常，退出检测";
                    xianshixinxi();
                    return false;
                }
                model.ASM.ASMgcsjZM objasmgcsjzm = new model.ASM.ASMgcsjZM();
                //上传实时过程数据
                //model.ASM.ASMgcsjZM objasmgcsj = new model.ASM.ASMgcsjZM();
                objasmgcsjzm.businessId = businessId;
                objasmgcsjzm.lineCode = m_mainform.lineCode;
                objasmgcsjzm.jcgcdysj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //objasmgcsjzm.imslsh = igcds++;// 90 + i + 1;
                objasmgcsjzm.m_SpeedGCSJ = m_fspeed;
                objasmgcsjzm.m_TrunGCSJ = itrun;
                objasmgcsjzm.m_PWGCSJ = (float)Math.Round((fForce * m_fspeed) / 360, 0);
                objasmgcsjzm.m_HCGCSJ = m_mainform.objfqy.m_iHc;
                objasmgcsjzm.m_COGCSJ = m_mainform.objfqy.m_fCo;
                objasmgcsjzm.m_CO2GCSJ = m_mainform.objfqy.m_fCo2;
                objasmgcsjzm.m_NOGCSJ = m_mainform.objfqy.m_iNo;
                objasmgcsjzm.m_O2GCSJ = m_mainform.objfqy.m_fO2;
                objasmgcsjzm.m_HCGCSJxz = (int)(getDF() * ((float)m_mainform.objfqy.m_iHc));
                objasmgcsjzm.m_COGCSJxz = (float)(getDF() * ((float)m_mainform.objfqy.m_fCo));
                objasmgcsjzm.m_CO2GCSJ = m_mainform.objfqy.m_fCo2;//问题，修正公式
                objasmgcsjzm.m_NOGCSJxz = (float)(getKH() * getDF() * (double)m_mainform.objfqy.m_iNo);
                objasmgcsjzm.m_O2GCSJ = m_mainform.objfqy.m_fO2;//问题，修正公式
                objasmgcsjzm.m_LAMDAGCSJ = m_mainform.objfqy.m_fLamda;
                objasmgcsjzm.m_DFGCSJ = (float)getDF();
                objasmgcsjzm.m_KHGCSJ = (float)getKH();
                objasmgcsjzm.m_lljqy = 0;//问题，                
                objasmgcsjzm.m_lljwd = 0;//问题，
                objasmgcsjzm.swendu = m_mainform.objfqy.m_fWenDu;
                objasmgcsjzm.sdaqiyi = m_mainform.objfqy.m_fYaLi;
                objasmgcsjzm.sshidu = m_mainform.objfqy.m_fShiDu;
                objasmgcsjzm.m_NLGCSJ = fForce;
                objasmgcsjzm.m_nlxzxs = 1;
                objasmgcsjzm.m_nlxs = 1;
                objasmgcsjzm.m_fyw = byw ? fywrg : m_mainform.objfqy.m_fyw;//油温

                objasmgcsjzm.m_WeightHC = m_mainform.objfqy.m_iHc * 130 / 224;
                objasmgcsjzm.m_WeightCO = m_mainform.objfqy.m_fCo * 280 / 224;
                objasmgcsjzm.m_WeightNO = m_mainform.objfqy.m_iNo * 300 / 224;
                objasmgcsjzm.m_ActPower = (float)Math.Round((fForce * m_fspeed) / 360, 0);

                objasmgcsjzm.GKLX = "0";//工况过程类型

                objasmgcsjzm.imslsh = igcsjds;// i + 1;//秒数流水号
                objasmgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjds).ToString("yyyy-MM-dd HH:mm:ss");
                taskgcsj = taskgcsj.ContinueWith(tgcsj =>
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (!bjiancestart)
                            return;
                        if (m_mainform.objbass.zmgcsjasm(businessId, objasmgcsjzm) == "1")
                        {
                            //izsj++;
                            break;
                        }
                        else
                        {
                            sxianshineirong = string.Format("过程数据联网失败。");
                            xianshixinxi();
                            sshanghang = string.Format("过程数据联网失败");
                            sxiahang = string.Format("");
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                            Thread.Sleep(200);
                            //return 4;
                        }
                    }
                });
                if (m_mainform.sfOBD)
                {
                    int iobdgcdsd = igcsjds;
                    taskgcsj = taskgcsj.ContinueWith(tobd =>
                    {
                        if (!bjiancestart)
                            return;
                        if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(iobdgcdsd).ToString("yyyy-MM-dd HH:mm:ss"), iobdgcdsd) == "1")
                        {
                            //iobdds++;
                        }
                        else
                        {
                            sxianshineirong = string.Format("OBD过程数据联网失败。");
                            xianshixinxi();
                            sshanghang = string.Format("OBD过程数据");
                            sxiahang = string.Format("联网失败");
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                            Thread.Sleep(200);
                            //return 4;
                        }
                    });
                }
                igcsjds++;
                //if (m_mainform.objbass.zmgcsjasm(businessId, objasmgcsjzm) == "1")
                //{
                //    //izsj++;
                //}
                System.Threading.Thread.Sleep(800);
            }
            sxianshineirong = "5025检测开始加速到25km/h";
            xianshixinxi();

            if (ztasm == 0)
            {
                m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "121");
                m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "221");
            }
            else
            {
                m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "1221");
                m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "2221");
            }
            sshanghang = string.Format("ASM5025检测开始");
            sxiahang = "加速到25km/h";
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            while (true)
            {

                Thread.Sleep(100);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                xianshiyibiao();
                if (m_fspeed > 6)
                {
                    break;
                }
            }
            if (PowerToSpeed(25, fjiazaiPower, 5 * 1000))//稳定5S的要求：底盘测功机模拟的惯量值在计时开始后持续3s超出所规定误差范围，工况计时器将重新开始计时（t=0s）                                                 
            {
                sendDate2 = DateTime.Now;
                fwendu = m_mainform.objfqy.m_fWenDu;
                fshidu = m_mainform.objfqy.m_fShiDu;
                fdaqiya = m_mainform.objfqy.m_fYaLi;
                igcsjcount = 1;
                float fAvgeForce = fjiazaiPower * 360 / 25;
                //m_mainform.objbass.uploadimage(businessId);
                m_mainform.objbass.uploadimage(businessId);
                m_mainform.objbass.GetPic("21");//安车拍照发送命令
                if (ztasm == 0)
                {
                    m_mainform.objbass.GetPic("121");
                    m_mainform.objbass.GetPic("221");
                }
                else
                {
                    m_mainform.objbass.GetPic("1221");
                    m_mainform.objbass.GetPic("2221");
                }
                // t3.Start();
                m_mainform.objfqy.bfqyco2 = true;
                #region
                for (int i = 0; i < 5; i++)
                {
                    int ireturn = 0;
                    if (m_mainform.sconnetname.Contains("智慧") || m_mainform.sconnetname.Contains("安车"))
                    {
                        igcsjds = i;
                        ireturn = guocheng5025(i, fForce25, 1, i, "1", 5);
                    }
                    else
                        ireturn = guocheng5025(i, fForce25, 1, 0, "1", 5);//1:正常2:重回90秒3:异常退出流程4:云景过程数据上传不上，重新过这一秒的数据
                    if (ireturn == 1)
                    {
                        igcsjds++;
                        continue;
                    }
                    else if (ireturn == 2)
                    {
                        igcsjds++;
                        i = 0;
                    }
                    else if (ireturn == 3)
                    {
                        return false;
                    }
                    else if (ireturn == 4)
                    {
                        i--;
                        continue;
                    }
                    else if (ireturn == 5)
                    {
                        return false;
                    }
                }
                #endregion
                #region 90秒流程

                int izjsj = 0;
                if (m_mainform.sconnetname.Contains("智慧") || m_mainform.sconnetname.Contains("安车"))
                    izjsj = 5;
                string GKLX = "3";
                bool bksjc = true;
                bool bpd5025 = true;
                for (int i = 0; i < 90; i++)
                {
                    if (igcsjds >= 145)
                    {
                        sxianshineirong = string.Format("检测总时间超过145秒");
                        xianshixinxi();

                        sshanghang = string.Format("检测总时间");
                        sxiahang = "超过145秒";
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        return false;
                    }
                    //if (izjsj < 10)
                    //    GKLX = "3";
                    //else 
                    if (bksjc && (i >= 10 && i < 20))
                        GKLX = "2";
                    else
                        GKLX = "3";
                    if (i >= 20)
                        bksjc = false;

                    int ireturn = guocheng5025(i, fForce25, 2, izjsj, GKLX, 90);
                    if (ireturn == 4)
                    {
                        i--;
                        continue;
                    }
                    if (i >= 9)
                    {
                        int ipd = pd5025(i, bksjc, izjsj);
                        //ipd = 2;//wwt20200524
                        if (ipd == 0)
                        {
                            bpd5025 = true;
                            return true;
                        }
                        else if (ipd == 2)
                        {
                            iHC25LS = iHC25;
                            iNO25LS = iNO25;
                            fCO25LS = fCO25;
                            lamda25LS = lamda25;
                            bpd5025 = false;
                        }
                        else if (ipd == 3)
                        {
                            bpd5025 = false;
                            return true;
                        }
                    }            

                    if (ireturn == 1)
                    {
                        izjsj++;
                        igcsjds++;
                    }
                    else if (ireturn == 2)
                    {
                        izjsj++;
                        igcsjds++;
                        i = 0;
                    }
                    else if (ireturn == 3)
                    {
                        return false;
                    }
                    else if (ireturn == 5)
                    {
                        return false;
                    }
                    else if (ireturn == 6)
                    {
                        return false;
                    }
                }
                #endregion
                #region 5025检测结束
                if (ztasm == 0)
                {
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "122");
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "222");
                }
                else
                {
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "1222");
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "2222");
                }
               
                //if ((!m_mainform.sconnetname.Contains("云景") && !b5025gk) || (iHC25 > iHCXZ25 || iNO25 > iNOXZ25 || fCO25 > fCOXZ25))//wwt--
                if (!bpd5025)
                {

                    ceshi = true;
                    lamda40 = 0;
                    //ASMType = "2";
                    m_mainform.objbass.GetPic("22");//安车拍照发送命令
                    if (ztasm == 0)
                    {
                        m_mainform.objbass.GetPic("122");
                        m_mainform.objbass.GetPic("222");
                    }
                    else
                    {
                        m_mainform.objbass.GetPic("1222");
                        m_mainform.objbass.GetPic("2222");
                    }

                    IsTenMCondition25 = 0;


                    if (!(iHC25 > iHCXZ25 || iNO25 > iNOXZ25 || fCO25 > fCOXZ25))
                    {
                        iHC25 = iHC25LS;
                        iNO25 = iNO25LS;
                        fCO25 = fCO25LS;
                        lamda25 = lamda25LS;
                    }

                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER5025={0},
                                                HCER5025={1},
                                                NOER5025={2},
                                                Gasturn25={3},
                                                A_QR25={4},
                                                Lamda25={5},
                                                GasWenDu={6},
                                                GasShiDu={7},
                                                GasYaLi={8},
                                                Time_begin='{9}',
                                                Time_end='{10}',
                                                WQPD={11}  
                                                where DETECT_ID={12}  or ASM_JYLSH='{13}' ",
                              fCO25,
                              iHC25,
                              iNO25,
                              m_TrunGCSJ25[0],
                              1,
                              m_LAMDAGCSJ25[0],
                              fwendu,
                              fshidu,
                              fdaqiya,
                              timeStart,
                              timeEnd,
                              1,
                              DETECT_ID,
                              businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    // bgood = false;
                    sxianshineirong = string.Format("进入2540检测");
                    xianshixinxi();

                    sshanghang = string.Format("进入2540检测");
                    sxiahang = "";
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    itime = 0;
                    xianshitime();
                    return StartGuoBiao2540();
                }
                else
                {
                    m_mainform.objbass.GetPic("22");//安车拍照发送命令
                    if (ztasm == 0)
                    {
                        m_mainform.objbass.GetPic("122");
                        m_mainform.objbass.GetPic("222");
                    }
                    else
                    {
                        m_mainform.objbass.GetPic("1222");
                        m_mainform.objbass.GetPic("2222");
                    }

                    Thread.Sleep(1000);
                    sxianshineirong = string.Format("5025检测合格");
                    xianshixinxi();

                    sshanghang = string.Format("5025检测合格");
                    sxiahang = "";
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    itime = 0;
                    xianshitime();
                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER5025={0},
                                                HCER5025={1},
                                                NOER5025={2},
                                                Gasturn25={3},
                                                A_QR25={4},
                                                Lamda25={5},
                                                GasWenDu={6},
                                                GasShiDu={7},
                                                GasYaLi={8},
                                                Time_begin='{9}',
                                                Time_end='{10}' ,
                                                WQPD={11}  
                                                where DETECT_ID={12}  or ASM_JYLSH='{13}' ",
                              fCO25,
                              iHC25,
                              iNO25,
                              m_TrunGCSJ25[0],
                              1,
                              m_LAMDAGCSJ25[0],
                              fwendu,
                              fshidu,
                              fdaqiya,
                              timeStart,
                              timeEnd,
                              1,
                              DETECT_ID,
                              businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                }
                #endregion
            }
            else
            {
                return false;
            }
            return true;
        }
        public double getKH()
        {
            double dKH=0;
            double Ra = m_mainform.objfqy.m_fShiDu;
            double Pd = 4.24;// 4132.982;//饱和蒸气压
            double Pb = m_mainform.objfqy.m_fYaLi;
            double ftest = (Pb - (Pd * Ra / 100));
            double ftest2 = 6.2111 * Ra * Pd;
            double H = (6.2111 * Ra * Pd / ((Pb - (Pd * Ra / 100)) > 0 ? (Pb - (Pd * Ra / 100)) : 1));
            dKH = (((1 / ((1 - 0.0329 * (H - 10.7)) > 0 ? (1 - 0.0329 * (H - 10.7)) : 1))) * 100) * 0.01;
            dKH = Math.Round(dKH, 2);

            return dKH;
        }
        public double getDF()
        {
            double fdf = 0;
            double d = 4.644;
            double fX = m_mainform.objfqy.m_fCo2 / ((m_mainform.objfqy.m_fCo2 + m_mainform.objfqy.m_fCo) > 0 ? (m_mainform.objfqy.m_fCo2 + m_mainform.objfqy.m_fCo) : 1);
            fdf = (((((fX / (d + 1.88 * fX)) / (m_mainform.objfqy.m_fCo2 > 0 ? m_mainform.objfqy.m_fCo2 : 1))) * 100));// * 0.01;
            fdf = Math.Round(fdf, 2);
            if (fdf > 3)
                fdf = 3;
            return fdf;
        }
        /// <summary>
        /// 5025每一秒过程
        /// </summary>
        /// <param name="i">倒数第几秒</param>
        /// <param name="fForce25">输出多少力</param>
        /// <param name="ilch">1：稳定时间5秒。2：正常流程90秒</param>
        /// <param name="izsj">总时间</param>
        /// <param name="GKLX">工况类型</param>
        /// <param name="gcsj">过程时间，稳定为5，流程为90</param>
        /// <returns>1:正常2:重回90秒3:异常退出流程4:云景过程数据上传不上，重新过这一秒的数据</returns>
        public int guocheng5025(int i, float fForce25,int ilch,int izsj,string GKLX,int gcsj)
        {
            sxianshineirong = string.Format("{1}还剩{0}秒", gcsj - i, ilch == 1 ? "稳定时间" : "5025");
            itime = gcsj - i;
            xianshixinxi();
            xianshitime();

            string sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "5025", m_fspeed);
            string sxiahang = string.Format("还剩{0}秒", gcsj - i);
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            DateTime dstart25 = DateTime.Now;
            model.ASM.ASMgcsjZM objasmgcsjzm = new model.ASM.ASMgcsjZM();
            while (true)
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                xianshiyibiao();
                {
                    sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "5025", m_fspeed);
                    sxiahang = string.Format("还剩{0}秒", gcsj - i);
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                {
                    Thread.Sleep(300);
                    m_HCGCSJ25[izsj] = m_mainform.objfqy.m_iHc;
                    m_COGCSJ25[izsj] = m_mainform.objfqy.m_fCo;
                    m_NOGCSJ25[izsj] = m_mainform.objfqy.m_iNo;
                    m_CO2GCSJ25[izsj] = m_mainform.objfqy.m_fCo2;
                    m_O2GCSJ25[izsj] = m_mainform.objfqy.m_fO2;
                    m_LAMDAGCSJ25[izsj] = m_mainform.objfqy.m_fLamda;
                    m_SpeedGCSJ25[izsj] = m_fspeed;

                    if (rbOBDZS.Checked)
                    {
                        m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                        int ifdjzs = 0;
                        int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                        itrun = ifdjzs;
                    }
                    else
                    {
                        itrun = m_mainform.objzsy.m_iGasturn;
                    }

                    if (itrun < 500 || itrun > 5000)
                    {
                        sxianshineirong = "转速异常，退出检测";
                        xianshixinxi();
                        return 5;
                    }
                    m_TrunGCSJ25[izsj] = itrun;
                    fForce = fForce25 + getRandom(0, 2);

                    float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iASMtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iASMtdz]);
                    float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iASMtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iASMtdy]);
                    float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iASMtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iASMtdh]);

                    fForce = fzou + fyou + fhou;
                    {
                        m_mainform.DAC.PutVol(shuchu);

                        string syy = DateTime.Now.ToString("yyyy");
                        string smm = DateTime.Now.ToString("MM");
                        string sdd = DateTime.Now.ToString("dd");
                        string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                        if (!Directory.Exists(smul))
                        {
                            Directory.CreateDirectory(smul);
                        }
                        string path = "";
                        path = string.Format("{0}\\{1}.ini", smul, "输出与力");

                        iniclass objini = new iniclass();
                        objini.Ini(path);
                        string siniwrite = string.Format("5025输出码值：{0}，速度：{1}，力：{2}", shuchu, m_fspeed.ToString("0.0"), fForce.ToString("0.0"));
                        Writue(hphm.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), siniwrite);
                    }


                    fForce = fForce25 + getRandom(0, 2);//没黑匣子的情况下修正

                    m_NLGCSJ25[izsj] = fForce;
                    m_PWGCSJ25[izsj] = (fForce * m_fspeed) / 360;
                    m_PWGCSJ25[izsj] = (float)Math.Round((double)m_PWGCSJ25[izsj], 0);
                    syouwen25[izsj] = byw ? fywrg : m_mainform.objfqy.m_fyw;

                    //m_mainform.gethuanjing();//读取数据库环境参数 
                    swendu25[izsj] = m_mainform.objfqy.m_fWenDu;
                    sdaqiyi25[izsj] = m_mainform.objfqy.m_fYaLi;
                    sshidu25[izsj] = m_mainform.objfqy.m_fShiDu;


                    count5025 = izsj;

                    m_DFGCSJ25[izsj] = getDF();// Math.Round(m_DFGCSJ25[i], 2);
                    //fwj20190421
                    if (m_DFGCSJ25[izsj] > 3.0)
                    {
                        m_DFGCSJ25[izsj] = 3.0;
                    }

                    m_KHGCSJ25[izsj] = getKH();// Math.Round(m_KHGCSJ25[i], 2);
                    m_ProcessTime25[izsj] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //-------------------------------------------------------------------------------------------------------------------


                    //结果修正
                    m_HCGCSJ25xz[izsj] = (int)((double)m_HCGCSJ25[izsj] * m_DFGCSJ25[izsj]);
                    if (m_mainform.sconnetname.Contains("安车"))
                    {
                        m_NOGCSJ25xz[izsj] = (int)((double)m_NOGCSJ25[izsj] * m_DFGCSJ25[izsj]);
                    }
                    else
                    {
                        m_NOGCSJ25xz[izsj] = (int)((double)m_NOGCSJ25[izsj] * m_DFGCSJ25[izsj] * m_KHGCSJ25[izsj]);
                    }
                    m_COGCSJ25xz[izsj] = (float)((double)m_COGCSJ25[izsj] * m_DFGCSJ25[izsj]);
                    m_NOGCSJ25xzxs[izsj] = (int)((double)m_NOGCSJ25[izsj] * m_KHGCSJ25[izsj]);

                    sudu[ileng] = (float)(m_mainform.objfqy.m_iHc);
                    gl[ileng] = m_mainform.objfqy.m_fCo;
                    f_sk[ileng] = (float)(m_mainform.objfqy.m_iNo);

                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", (fForce * m_fspeed) / 360);

                    WriteGraphEX(zg, ssudu, sgl, ileng);
                    ileng++;

                    //  ileng++;

                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                        sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                        xianshixinxi();
                        sshanghang = string.Format("找不到OBD");
                        sxiahang = string.Format("请接好OBD");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        return 3;
                    }
                    iobd = igcsjds;
                    OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                    OBD_fh[iobd] = m_mainform.OBD_fh;
                    OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                    OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                    OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                    OBD_cs[iobd] = m_mainform.OBD_cs;
                    OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                    OBD_jql[iobd] = m_mainform.OBD_jql;
                    OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                    OBD_scgl[iobd] = m_mainform.OBD_scgl;
                    OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                    OBD_hyl[iobd] = m_mainform.OBD_hyl;
                    OBD_no[iobd] = m_mainform.OBD_no;
                    OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                    OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                    OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                    OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                    OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                    OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                    //上传实时过程数据
                    //model.ASM.ASMgcsjZM objasmgcsj = new model.ASM.ASMgcsjZM();
                    objasmgcsjzm.businessId = businessId;//受理编码
                    objasmgcsjzm.lineCode = m_mainform.lineCode;//检测站编码
                    objasmgcsjzm.jcgcdysj = DateTime.Now.ToString("yyyy-MM-ddHH:mm:ss");//检测过程数据对应时间
                    //objasmgcsjzm.imslsh = igcds++;// i + 1;//秒数流水号
                    objasmgcsjzm.m_SpeedGCSJ = m_SpeedGCSJ25[izsj];//逐秒的车速
                    objasmgcsjzm.m_TrunGCSJ = m_TrunGCSJ25[izsj];//逐秒发动机转速
                    objasmgcsjzm.m_PWGCSJ = m_PWGCSJ25[izsj];//逐秒底盘测功机负载
                    objasmgcsjzm.m_HCGCSJ = m_HCGCSJ25[izsj];//逐秒HC浓度值(未经修正)
                    objasmgcsjzm.m_COGCSJ = m_COGCSJ25[izsj];//逐秒CO浓度值(未经修正)
                    objasmgcsjzm.m_CO2GCSJ = m_CO2GCSJ25[izsj];//逐秒CO2浓度值(未经修正)
                    objasmgcsjzm.m_NOGCSJ = m_NOGCSJ25[izsj];//逐秒NO浓度值(未经修正)
                    objasmgcsjzm.m_O2GCSJ = m_O2GCSJ25[izsj];//逐秒O2浓度值(未经修正)
                    objasmgcsjzm.m_HCGCSJxz = m_HCGCSJ25xz[izsj];//逐秒HC浓度值(修正后)
                    objasmgcsjzm.m_COGCSJxz = m_COGCSJ25xz[izsj];//逐秒CO浓度值(修正后)
                    objasmgcsjzm.m_CO2GCSJ = m_CO2GCSJ25[izsj];//逐秒CO2浓度值(修正后)
                    objasmgcsjzm.m_NOGCSJxz = m_NOGCSJ25xz[izsj];//逐秒NO浓度值(修正后)
                    objasmgcsjzm.m_O2GCSJ = m_O2GCSJ25[izsj];//逐秒O2浓度值(修正后)
                    objasmgcsjzm.m_LAMDAGCSJ = m_LAMDAGCSJ25[izsj];//逐秒计算的λ值
                    objasmgcsjzm.m_DFGCSJ = (float)m_DFGCSJ25[izsj];//逐秒稀释修正系数DF
                    objasmgcsjzm.m_KHGCSJ = (float)m_KHGCSJ25[izsj];//NO湿度修正系数
                    objasmgcsjzm.m_lljqy = 0;//测试工况流量计气压力每秒数据      
                    objasmgcsjzm.m_lljwd = 0;//测试工况流量计温度每秒数据
                    objasmgcsjzm.swendu = swendu25[izsj];//测试工况环境温度每秒数据
                    objasmgcsjzm.sdaqiyi = sdaqiyi25[izsj];//测试工况环境大气压力每秒数据
                    objasmgcsjzm.sshidu = sshidu25[izsj];//测试工况环境相对湿度每秒数据
                    objasmgcsjzm.m_NLGCSJ = m_NLGCSJ25[izsj];//扭力
                    objasmgcsjzm.m_nlxzxs = 1;//扭力校准系数
                    objasmgcsjzm.m_nlxs = 1;//扭力系数
                    objasmgcsjzm.m_fyw = syouwen25[izsj];//油温

                    objasmgcsjzm.m_WeightHC = m_HCGCSJ25[izsj] * 130 / 224;
                    objasmgcsjzm.m_WeightCO = m_COGCSJ25[izsj] * 280 / 224;
                    objasmgcsjzm.m_WeightNO = m_NOGCSJ25[izsj] * 300 / 224;
                    objasmgcsjzm.m_ActPower = m_PWGCSJ25[izsj];// *m_SpeedGCSJ25[i] / 360;

                    objasmgcsjzm.GKLX = GKLX;//工况过程类型
                    igcsjcount++;
                    /////云景过程数据
                    if (sASMllgd.Contains("是"))// && i > 7)
                    {
                       // return 1;//test
                        if (diliulangyujing(m_mainform.objfqy.m_fCo + m_mainform.objfqy.m_fCo2))
                        {
                            return 3;
                        }

                    }
                    inspectNum++;
                    m_mainform.baocunrijiGCSJ(string.Format("{0}ASM5025过程数据日志", hphm.Text),
                    string.Format("HC:{0},CO:{1},NO:{2},速度:{3},油温:{4},CO+CO2:{5}",
                    m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo, m_mainform.objfqy.m_iNo, m_mainform.m_fspeed, byw ? fywrg : m_mainform.objfqy.m_fyw, (m_mainform.objfqy.m_fCo + m_mainform.objfqy.m_fCo2)));

                }

                //if ((DateTime.Now - dstart25).TotalMilliseconds > 700)
                {
                    //ddatagcsj = DateTime.Now;
                    objasmgcsjzm.imslsh = igcsjds;// i + 1;//秒数流水号
                    objasmgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjds).ToString("yyyy-MM-dd HH:mm:ss");

                    taskgcsj = taskgcsj.ContinueWith(tgcsj =>
                    {
                        for (int b = 0; b < 3; b++)
                        {
                            if (!bjiancestart)
                                return;
                            if (m_mainform.objbass.zmgcsjasm(businessId, objasmgcsjzm) == "1")
                            {
                                //izsj++;
                                break;
                            }
                            else
                            {
                                sxianshineirong = string.Format("过程数据联网失败。");
                                xianshixinxi();
                                sshanghang = string.Format("过程数据联网失败");
                                sxiahang = string.Format("");
                                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                                Thread.Sleep(200);
                                //return 4;
                            }
                        }
                    });
                    if (m_mainform.sfOBD)
                    {
                        int iobdgcdsd = igcsjds;
                        taskgcsj = taskgcsj.ContinueWith(tobd =>
                        {
                            if (!bjiancestart)
                                return;
                            if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(iobdgcdsd).ToString("yyyy-MM-dd HH:mm:ss"), iobdgcdsd) == "1")
                            {
                                //iobdds++;
                            }
                            else
                            {
                                sxianshineirong = string.Format("OBD过程数据联网失败。");
                                xianshixinxi();
                                sshanghang = string.Format("OBD过程数据");
                                sxiahang = string.Format("联网失败");
                                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                                Thread.Sleep(200);
                                //return 4;
                            }
                        });
                    }
                    break;
                }
            }


            if (m_fspeed < 23 || m_fspeed > 27)
            {

                //if (sASMzs.Contains("是"))
                {
                    if (icccs > 2)
                    {
                        //i = 0;
                        sxianshineirong = string.Format("{1}还剩{0}秒", gcsj - i, ilch == 1 ? "稳定时间" : "5025");
                        xianshixinxi();
                        {
                            sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "5025", m_fspeed);
                            sxiahang = string.Format("还剩{0}秒", gcsj - i);
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        }
                        itime = gcsj - i;
                        xianshitime();
                        if ((gcsj == 90) && (gcsj - i < 80))
                        {
                            sxianshineirong = "速度超范围，退出检测";
                            xianshixinxi();
                            return 6;
                        }
                        return 2;
                    }
                    icccs++;
                    if (iljcccs > 5)
                    {
                        //i = 0;
                        iljcccs = 0;
                        sxianshineirong = string.Format("{1}还剩{0}秒", gcsj - i, ilch == 1 ? "稳定时间" : "5025");
                        xianshixinxi();
                        {
                            sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "5025", m_fspeed);
                            sxiahang = string.Format("还剩{0}秒", gcsj - i);
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        }
                        itime = gcsj - i;
                        xianshitime();
                        if ((gcsj == 90) && (gcsj - i < 80))
                        {
                            sxianshineirong = "速度超范围，退出检测";
                            xianshixinxi();
                            return 6;
                        }
                        return 2;
                    }
                    iljcccs++;
                }
                //else
                //{
                //    if (i > 0)
                //    {
                //        i--;

                //    }
                //    else
                //    {
                //        i = 0;
                //    }
                //}
            }
            else
            {
                icccs = 0;
            }
            int iyysj = (int)(DateTime.Now - dstart25).TotalMilliseconds;
            if (iyysj < 900)
            {
                Thread.Sleep(900 - iyysj);
            }
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
            xianshiyibiao();
            return 1;
        }

        /// <summary>
        /// 判定过程5025
        /// </summary>
        /// <param name="i"></param>
        /// <param name="bksjc"></param>
        /// <param name="izjsj"></param>
        /// <returns>1：当次数据合格2：当次数据不合格0：快速检测合格3：超过限值5倍</returns>
        public int pd5025(int i, bool bksjc, int izjsj)
        {

            //判断快速10秒是否合格 第15秒到第25秒数据是否合格
            if (i == 19 && bksjc)
            {
                bksjc = false;
                lamda40 = 0;
                ASMType = "1";
                //结果修正
                double dhc25 = 0;
                double dno25 = 0;
                double dco25 = 0;
                for (int j = izjsj - 9; j <= izjsj; j++)
                {
                    dhc25 = dhc25 + m_HCGCSJ25xz[j];// * m_DFGCSJ25[j];
                    dno25 = dno25 + m_NOGCSJ25xz[j];// * m_DFGCSJ25[j] * m_KHGCSJ25[j];
                    dco25 = dco25 + m_COGCSJ25xz[j];// * m_DFGCSJ25[j];
                    lamda25 = lamda25 + m_LAMDAGCSJ25[j];
                }
                iHC25 = (int)(dhc25 / 10);
                iNO25 = (int)(dno25 / 10);
                fCO25 = (float)(dco25 / 10);
                lamda25 = lamda25 / 10;



                fdjzs5025 = itrun;//发动机转速
                fdjyw5025 = byw ? fywrg : m_mainform.objfqy.m_fyw;//油温
                if(iHC25 < iHCXZ25 * 0.5 && iNO25 < iNOXZ25 * 0.5 && fCO25 < fCOXZ25 * 0.5)//test
                {

                    sxianshineirong = string.Format("快速检测合格检测结束");
                    xianshixinxi();

                    string sshanghang = string.Format("快速检测合格");
                    string sxiahang = string.Format("检测结束");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER5025={0},
                                                HCER5025={1},
                                                NOER5025={2},
                                                Gasturn25={3},
                                                A_QR25={4},
                                                Lamda25={5},
                                                GasWenDu={6},
                                                GasShiDu={7},
                                                GasYaLi={8},
                                                Time_begin='{9}',
                                                Time_end='{10}'  ,
                                                WQPD={11}
                                                where DETECT_ID={12} or ASM_JYLSH='{13}'  ",
                                  fCO25,
                                  iHC25,
                                  iNO25,
                                  m_TrunGCSJ25[0],
                                  1,
                                  m_LAMDAGCSJ25[0],
                                  fwendu,
                                  fshidu,
                                  fdaqiya,
                                  timeStart,
                                  timeEnd,
                                  1,
                                  DETECT_ID,
                                  businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    m_mainform.objbass.GetPic("22");//安车拍照发送命令
                    m_mainform.objbass.GetPic("122");
                    m_mainform.objbass.GetPic("222");
                    return 0;
                }
                else if (iHC25 > iHCXZ25 || iNO25 > iNOXZ25 || fCO25 > fCOXZ25)
                {
                    iHC25LS = iHC25;
                    iNO25LS = iNO25;
                    fCO25LS = fCO25;
                    lamda25LS = lamda25;
                    return 2;
                }
                else
                {
                    return 1;
                }
            }
            else
            {
                if (m_mainform.sconnetname.Contains("安车")&&i<19)
                {
                    return 1;
                }
                lamda40 = 0;
                ASMType = "2";
                IsTenMCondition25 = 0;
                //int j = 0;
                //结果修正
                //if (sASMJGXZ.Contains("是"))
                {
                    double dhc25 = 0;
                    double dno25 = 0;
                    double dco25 = 0;

                    for (int j = izjsj - 9; j <= izjsj; j++)
                    {
                        dhc25 = dhc25 + m_HCGCSJ25xz[j];// * m_DFGCSJ25[j];
                        dno25 = dno25 + m_NOGCSJ25xz[j];// * m_DFGCSJ25[j] * m_KHGCSJ25[j];
                        dco25 = dco25 + m_COGCSJ25xz[j];// * m_DFGCSJ25[j];
                        lamda25 = lamda25 + m_LAMDAGCSJ25[j];
                    }
                    iHC25 = (int)(dhc25 / 10);
                    iNO25 = (int)(dno25 / 10);
                    fCO25 = (float)(dco25 / 10);
                    lamda25 = lamda25 / 10;
                }
                if(iHC25 > iHCXZ25 * 5 || iNO25 > iNOXZ25 * 5 || fCO25 > fCOXZ25 * 5f)
                {
                    m_mainform.objbass.GetPic("22");//安车拍照发送命令
                    m_mainform.objbass.GetPic("122");
                    m_mainform.objbass.GetPic("222");
                    bgood = false;
                    sxianshineirong = string.Format("检测不合格检测结束");
                    xianshixinxi();

                    string sshanghang = string.Format("检测不合格");
                    string sxiahang = string.Format("检测结束");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                   COER5025={0},
                                                   HCER5025={1},
                                                   NOER5025={2},
                                                   Gasturn25={3},
                                                   A_QR25={4},
                                                   Lamda25={5},
                                                   GasWenDu={6},
                                                   GasShiDu={7},
                                                   GasYaLi={8},
                                                   Time_begin='{9}',
                                                   Time_end='{10}' ,
                                                   WQPD={11}
                                                   where DETECT_ID={12}  or ASM_JYLSH='{13}' ",
                             fCO25,
                             iHC25,
                             iNO25,
                             m_TrunGCSJ25[0],
                             1,
                             m_LAMDAGCSJ25[0],
                             fwendu,
                             fshidu,
                             fdaqiya,
                             timeStart,
                             timeEnd,
                             2,
                             DETECT_ID,
                             businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    return 3;
                }

                else if (iHC25 > iHCXZ25 || iNO25 > iNOXZ25 || fCO25 > fCOXZ25)
                {
                    ////b5025gk = false;
                    iHC25LS = iHC25;
                    iNO25LS = iNO25;
                    fCO25LS = fCO25;
                    lamda25LS = lamda25;
                    return 2;
                }
                else
                    return 1;
            }
        }
        public bool StartGuoBiao2540()//国标
        {
            DateTime dcomfh = DateTime.Now;
            IsTenMCondition40 = 1;
            xianshiyibiao25xs();
            xianshiyibiao40xs();

            b2540 = true;
            icccs = 0;
            iljcccs = 0;
            float Ra = 0;
            double Pd = 0;
            double Pb = 0;

            //float fjiazaiPower = izbzl / 185;//加载的功率
            float fjiazaiPower = (float)izbzl / 185f;//加载的功率
            //if (fjiazaiPower < 1 || fjiazaiPower > 20)
            //{
            //    fjiazaiPower = 10;//测试使用
            //}

            if (scllx.Contains("重"))
            {
                if (fjiazaiPower > 25)
                {
                    fjiazaiPower = 25;
                }
            }
            else
            {
                if (fjiazaiPower < 1 || fjiazaiPower > 20)
                {
                    fjiazaiPower = 10;//测试使用
                }

            }

            jzzgl2540 = fjiazaiPower;
            //P5025-2=RM / 148
            //P2540-2=RM / 185
            //式中：RM—基准质量，kg；
            //P5025-2—滚筒直径为218mm±2mm的测功机ASM5025工况设定功率值，kW；
            //P2540-2—滚筒直径为218mm±2mm的测功机ASM2540工况设定功率值，kW。
            //对重型车，如果P5025-2或P2540-2的加载功率计算结果大于或等于25.0kW，均按25.0kW进行加载测试。


            float fForce40 = fjiazaiPower * 360f / 40f;

            ////////////////加速到40公里
            float fX = 0;
            double d = 4.644;//////汽油车d=4.644;压缩天然气--6.64,液化石油气--5.39
            double k;
            double H;
            H = 43.478 * Ra * Pd / (Pb - (Pd * Ra / 100));
            k = 1 / (1 - 0.0047 * (H - 75));
            sxianshineirong = "ASM2540检测开始加速到40km/h";
            xianshixinxi();
            {
                if (ztasm == 0)
                {
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "123");
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "223");
                }
                else
                {
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "1223");
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "2223");
                }


                string sshanghang = string.Format("ASM2540检测开始");
                string sxiahang = string.Format("加速到40km/h");
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            }
            int i5025ds = igcsjds;
            if (PowerToSpeed(40, fjiazaiPower, 5 * 1000))//稳定5S的要求：底盘测功机模拟的惯量值在计时开始后持续3s超出所规定误差范围，工况计时器将重新开始计时（t=0s）   
            {
                float fAvgeForce = fjiazaiPower * 360 / 40;

                m_mainform.objbass.GetPic("23");//安车拍照发送命令
                if (ztasm == 0)
                {
                    m_mainform.objbass.GetPic("123");
                    m_mainform.objbass.GetPic("223");
                }
                else
                {
                    m_mainform.objbass.GetPic("1223");
                    m_mainform.objbass.GetPic("2223");
                }
                //DateTime dtgcsj = DateTime.Now;
                //int igcsjcount = 1;
                #region
                for (int i = 0; i < 5; i++)
                {
                    int ireturn = 0;
                    if (m_mainform.sconnetname.Contains("智慧") || m_mainform.sconnetname.Contains("安车"))
                    {
                        igcsjds = i;
                        ireturn = guocheng2540(i, fForce40, 1, i, "4", 5);
                    }
                    else
                        ireturn = guocheng2540(i, fForce40, 1, 0, "4", 5);//1:正常2:重回90秒3:异常退出流程4:云景过程数据上传不上，重新过这一秒的数据
                    if (ireturn == 1)
                    {
                        igcsjds++;
                        continue;
                    }
                    else if (ireturn == 2)
                    {
                        igcsjds++;
                        i = 0;
                    }
                    else if (ireturn == 3)
                    {
                        return false;
                    }
                    else if (ireturn == 4)
                    {
                        i--;
                        continue;
                    }
                    else if (ireturn == 5)
                    {
                        return false;
                    }
                }
                #endregion
                #region 90秒流程
                int izjsj = 0;
                if (m_mainform.sconnetname.Contains("智慧") || m_mainform.sconnetname.Contains("安车"))
                    izjsj = 5;
                string GKLX = "6";
                bool bksjc = true;
                bool bpd2540 = true;
                for (int i = 0; i < 90; i++)
                {
                    if (igcsjds - i5025ds >= 145)
                    {
                        sxianshineirong = string.Format("检测总时间超过145秒");
                        xianshixinxi();
                        {
                            string sshanghang = string.Format("检测总时间");
                            string sxiahang = string.Format("超过145秒");
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        }
                        return false;
                    }
                    //if (izjsj < 10)
                    //    GKLX = "6";
                    //else 
                    if (bksjc && (i >= 10 && i < 20))
                        GKLX = "5";
                    else
                        GKLX = "6";
                    if (i >= 20)
                        bksjc = false;
                    int ireturn = guocheng2540(i, fForce40, 2, izjsj, GKLX, 90);
                    if (ireturn == 4)
                    {
                        i--;
                        continue;
                    }
                    if (i >= 9)
                    {
                        int ipd = pd2540(i, bksjc, izjsj);
                        //ipd = 1;//wwt20200524
                        if (ipd == 0)
                        {
                            break;
                        }
                        else if (ipd == 2)
                        {
                            bpd2540 = false;
                            break;
                        }
                        else if (ipd == 3)
                        {
                            bpd2540 = false;
                            break;
                        }
                    }

                    if (ireturn == 1)
                    {
                        izjsj++;
                        igcsjds++;
                    }
                    else if (ireturn == 2)
                    {
                        izjsj++;
                        igcsjds++;
                        i = 0;
                    }
                    else if (ireturn == 3)
                    {
                        return false;
                    }
                    else if (ireturn == 5)
                    {
                        return false;
                    }
                    else if (ireturn == 6)
                    {
                        return false;
                    }
                }
                #endregion
                #region 2540检测结束
                if (ztasm == 0)
                {
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "124");
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "224");
                }
                else
                {
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "1224");
                    m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "2224");
                }
                
                //if ((!m_mainform.sconnetname.Contains("云景") && !b5025gk) || (iHC25 > iHCXZ25 || iNO25 > iNOXZ25 || fCO25 > fCOXZ25))//wwt--
                if (!bpd2540)
                //if (iHC40 > iHCXZ40 || iNO40 > iNOXZ40 || fCO40 > fCOXZ40)
                {
                    m_mainform.objbass.GetPic("24");//安车拍照发送命令
                    if (ztasm == 0)
                    {
                        m_mainform.objbass.GetPic("124");
                        m_mainform.objbass.GetPic("224");
                    }
                    else
                    {
                        m_mainform.objbass.GetPic("1224");
                        m_mainform.objbass.GetPic("2224");
                    }
                    bgood = false;
                    sxianshineirong = string.Format("检测不合格检测结束");
                    xianshixinxi();

                    {
                        string sshanghang = string.Format("检测不合格");
                        string sxiahang = string.Format("检测结束");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER2540={0},
                                                HCER2540={1},
                                                NOER2540={2},
                                                Gasturn40={3},
                                                Lamda40={4},
                                                Time_begin='{5}',
                                                Time_end='{6}',
                                                WQPD={7}
                                                where DETECT_ID={8}  or ASM_JYLSH='{9}' ",
                                   fCO40,
                                   iHC40,
                                   iNO40,
                                   m_TrunGCSJ40[0],
                                   m_LAMDAGCSJ40[0],
                                   timeStart,
                                   timeEnd,
                                   2,
                                   DETECT_ID,
                                   businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    return true;
                }
                else
                {
                    m_mainform.objbass.GetPic("24");//安车拍照发送命令
                    if (ztasm == 0)
                    {
                        m_mainform.objbass.GetPic("124");
                        m_mainform.objbass.GetPic("224");
                    }
                    else
                    {
                        m_mainform.objbass.GetPic("1224");
                        m_mainform.objbass.GetPic("2224");
                    }
                    sxianshineirong = string.Format("ASM2540检测合格");
                    xianshixinxi();

                    {
                        string sshanghang = string.Format("ASM2540");
                        string sxiahang = string.Format("检测合格");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER2540={0},
                                                HCER2540={1},
                                                NOER2540={2},
                                                Gasturn40={3},
                                                Lamda40={4},
                                                Time_begin='{5}',
                                                Time_end='{6}',
                                                WQPD={7}
                                                where DETECT_ID={8} or ASM_JYLSH='{9}'  ",
                                  fCO40,
                                  iHC40,
                                  iNO40,
                                  m_TrunGCSJ40[0],
                                  m_LAMDAGCSJ40[0],
                                  timeStart,
                                  timeEnd,
                                  1,
                                  DETECT_ID,
                                  businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    return true;
                }
                #endregion
            }
            else
            {
                return false;
            }
            return true;
        }


        /// <summary>
        /// 2540每一秒过程
        /// </summary>
        /// <param name="i">倒数第几秒</param>
        /// <param name="fForce25">输出多少力</param>
        /// <param name="ilch">1：稳定时间5秒。2：正常流程90秒</param>
        /// <param name="izsj">总时间</param>
        /// <param name="GKLX">工况类型</param>
        /// <param name="gcsj">过程时间，稳定为5，流程为90</param>
        /// <returns>1:正常2:重回90秒3:异常退出流程4:云景过程数据上传不上，重新过这一秒的数据</returns>
        public int guocheng2540(int i, float fForce40, int ilch, int izsj, string GKLX, int gcsj)
        {
            sxianshineirong = string.Format("{1}还剩{0}秒", gcsj - i, ilch == 1 ? "稳定时间" : "2540");
            itime = gcsj - i;
            xianshixinxi();
            xianshitime();

            {
                string sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "2540", m_fspeed);
                string sxiahang = string.Format("还剩{0}秒", gcsj - i);
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            }
            DateTime dstart40 = DateTime.Now;
            model.ASM.ASMgcsjZM objasmgcsjzm = new model.ASM.ASMgcsjZM();
            while (true)
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                xianshiyibiao40();
                Thread.Sleep(300);
                {

                    m_HCGCSJ40[izsj] = m_mainform.objfqy.m_iHc;
                    m_COGCSJ40[izsj] = m_mainform.objfqy.m_fCo;
                    m_NOGCSJ40[izsj] = m_mainform.objfqy.m_iNo;
                    m_CO2GCSJ40[izsj] = m_mainform.objfqy.m_fCo2;
                    m_O2GCSJC40[izsj] = m_mainform.objfqy.m_fO2;
                    m_LAMDAGCSJ40[izsj] = m_mainform.objfqy.m_fLamda;
                    m_SpeedGCSJ40[izsj] = m_fspeed;

                    if (rbOBDZS.Checked)
                    {
                        int ifdjzs = 0;
                        int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                        itrun = ifdjzs;
                    }
                    else
                    {
                        itrun = m_mainform.objzsy.m_iGasturn;
                    }
                    if (itrun < 500 || itrun > 5000)
                    {
                        sxianshineirong = "转速异常，退出检测";
                        xianshixinxi();
                        return 5;
                    }
                    m_TrunGCSJ40[izsj] = itrun;

                    float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iASMtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iASMtdz]);
                    float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iASMtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iASMtdy]);
                    float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iASMtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iASMtdh]);

                    fForce = fzou + fyou + fhou;

                    {
                        m_mainform.DAC.PutVol(shuchu);

                        string syy = DateTime.Now.ToString("yyyy");
                        string smm = DateTime.Now.ToString("MM");
                        string sdd = DateTime.Now.ToString("dd");
                        string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                        if (!Directory.Exists(smul))
                        {
                            Directory.CreateDirectory(smul);
                        }
                        string path = "";
                        path = string.Format("{0}\\{1}.ini", smul, "输出与力");

                        iniclass objini = new iniclass();
                        objini.Ini(path);
                        string siniwrite = string.Format("2540输出码值：{0}，速度：{1}，力：{2}", shuchu, m_fspeed.ToString("0.0"), fForce.ToString("0.0"));
                        Writue(hphm.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), siniwrite);
                    }

                    fForce = fForce40 + getRandom(0, 2);
                    m_NLGCSJ40[izsj] = fForce;

                    m_PWGCSJ40[izsj] = (fForce * m_fspeed) / 360;
                    m_PWGCSJ40[izsj] = (float)Math.Round(m_PWGCSJ40[izsj], 0);
                    syouwen40[izsj] = byw ? fywrg : m_mainform.objfqy.m_fyw;

                    swendu40[izsj] = m_mainform.objfqy.m_fWenDu;
                    sdaqiyi40[izsj] =m_mainform.objfqy.m_fYaLi ;
                    sshidu40[izsj] = m_mainform.objfqy.m_fShiDu;
                    count2540 = izsj;


                    m_DFGCSJ40[izsj] = getDF();// Math.Round(m_DFGCSJ40[i], 2);
                    if (m_DFGCSJ40[izsj] > 3.0)
                    {
                        m_DFGCSJ40[izsj] = 3.0;
                    }

                    m_KHGCSJ40[izsj] = getKH();// Math.Round(m_KHGCSJ40[i], 2);
                    m_ProcessTime40[izsj] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //-------------------------------------------------------------------------------------------------------------------

                    m_HCGCSJ40xz[izsj] = (int)((double)m_HCGCSJ40[izsj] * m_DFGCSJ40[izsj]);
                    if (m_mainform.sconnetname.Contains("安车"))
                    {
                        m_NOGCSJ40xz[izsj] = (int)((double)m_NOGCSJ40[izsj] * m_DFGCSJ40[izsj]);
                    }
                    else
                    {
                        m_NOGCSJ40xz[izsj] = (int)((double)m_NOGCSJ40[izsj] * m_DFGCSJ40[izsj] * m_KHGCSJ40[izsj]);
                    }
                    m_COGCSJ40xz[izsj] = (float)((double)m_COGCSJ40[izsj] * m_DFGCSJ40[izsj]);
                    m_NOGCSJ40xzxs[izsj] = (int)((double)m_NOGCSJ40[izsj] * m_KHGCSJ40[izsj]);



                    sudu[ileng] = (float)(m_mainform.objfqy.m_iHc);
                    gl[ileng] = m_mainform.objfqy.m_fCo;
                    f_sk[ileng] = (float)(m_mainform.objfqy.m_iNo);
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", (fForce * m_fspeed) / 360);

                    WriteGraphEX(zg, ssudu, sgl, ileng);
                    ileng++;

                    //WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);


                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                        sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                        xianshixinxi();
                        {
                            string sshanghang = string.Format("找不到OBD");
                            string sxiahang = string.Format("请接好OBD");
                            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        }
                        return 3;
                    }
                    if (m_mainform.sconnetname.Contains("智慧") || m_mainform.sconnetname.Contains("安车"))
                        iobd = 95 + izsj;
                    else
                    iobd = igcsjds;// 90 + izsj;

                    OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                    OBD_fh[iobd] = m_mainform.OBD_fh;
                    OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                    OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                    OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                    OBD_cs[iobd] = m_mainform.OBD_cs;
                    OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                    OBD_jql[iobd] = m_mainform.OBD_jql;
                    OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                    OBD_scgl[iobd] = m_mainform.OBD_scgl;
                    OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                    OBD_hyl[iobd] = m_mainform.OBD_hyl;
                    OBD_no[iobd] = m_mainform.OBD_no;
                    OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                    OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                    OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                    OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                    OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                    OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                    m_mainform.baocunrijiGCSJ(string.Format("{0}ASM2540过程数据日志", hphm.Text),
                    string.Format("HC:{0},CO:{1},NO:{2},速度:{3},油温:{4},CO+CO2:{5}",
                    m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo, m_mainform.objfqy.m_iNo, m_mainform.m_fspeed, byw ? fywrg : m_mainform.objfqy.m_fyw, (m_mainform.objfqy.m_fCo + m_mainform.objfqy.m_fCo2)));


                    //上传实时过程数据
                    //model.ASM.ASMgcsjZM objasmgcsj = new model.ASM.ASMgcsjZM();
                    objasmgcsjzm.businessId = businessId;
                    objasmgcsjzm.lineCode = m_mainform.lineCode;
                    objasmgcsjzm.jcgcdysj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //objasmgcsjzm.imslsh = igcds++;// 90 + i + 1;
                    objasmgcsjzm.m_SpeedGCSJ = m_SpeedGCSJ40[izsj];
                    objasmgcsjzm.m_TrunGCSJ = m_TrunGCSJ40[izsj];
                    objasmgcsjzm.m_PWGCSJ = m_PWGCSJ40[izsj];
                    objasmgcsjzm.m_HCGCSJ = m_HCGCSJ40[izsj];
                    objasmgcsjzm.m_COGCSJ = m_COGCSJ40[izsj];
                    objasmgcsjzm.m_CO2GCSJ = m_CO2GCSJ40[izsj];
                    objasmgcsjzm.m_NOGCSJ = m_NOGCSJ40[izsj];
                    objasmgcsjzm.m_O2GCSJ = m_O2GCSJC40[izsj];
                    objasmgcsjzm.m_HCGCSJxz = m_HCGCSJ40xz[izsj];
                    objasmgcsjzm.m_COGCSJxz = m_COGCSJ40xz[izsj];
                    objasmgcsjzm.m_CO2GCSJ = m_CO2GCSJ40[izsj];//问题，修正公式
                    objasmgcsjzm.m_NOGCSJxz = m_NOGCSJ40xz[izsj];
                    objasmgcsjzm.m_O2GCSJ = m_O2GCSJC40[izsj];//问题，修正公式
                    objasmgcsjzm.m_LAMDAGCSJ = m_LAMDAGCSJ40[izsj];
                    objasmgcsjzm.m_DFGCSJ = (float)m_DFGCSJ40[izsj];
                    objasmgcsjzm.m_KHGCSJ = (float)m_KHGCSJ40[izsj];
                    objasmgcsjzm.m_lljqy = 0;//问题，                
                    objasmgcsjzm.m_lljwd = 0;//问题，
                    objasmgcsjzm.swendu = swendu40[izsj];
                    objasmgcsjzm.sdaqiyi = sdaqiyi40[izsj];
                    objasmgcsjzm.sshidu = sshidu40[izsj];
                    objasmgcsjzm.m_NLGCSJ = m_NLGCSJ40[izsj];
                    objasmgcsjzm.m_nlxzxs = 1;
                    objasmgcsjzm.m_nlxs = 1;
                    objasmgcsjzm.m_fyw = syouwen40[izsj];//油温

                    objasmgcsjzm.m_WeightHC = m_HCGCSJ40[izsj] * 130 / 224;
                    objasmgcsjzm.m_WeightCO = m_COGCSJ40[izsj] * 280 / 224;
                    objasmgcsjzm.m_WeightNO = m_NOGCSJ40[izsj] * 300 / 224;
                    objasmgcsjzm.m_ActPower = m_PWGCSJ40[izsj];// *m_SpeedGCSJ25[i] / 360;

                    objasmgcsjzm.GKLX = GKLX;//工况过程类型
                    //objasmgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                    //m_mainform.objbass.zmgcsjasm(businessId, objasmgcsj);
                    //if (m_mainform.sfOBD)
                    //{
                    //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objasmgcsj.imslsh);
                    //}
                    igcsjcount++;
                    if (sASMllgd.Contains("是"))// && i > 7)
                    {
                        //return 1;//test
                        if (diliulangyujing(m_mainform.objfqy.m_fCo + m_mainform.objfqy.m_fCo2))
                        {
                            return 3;
                        }
                    }

                }

                //if ((DateTime.Now - dstart40).TotalMilliseconds > 700)
                {
                    //ddatagcsj = DateTime.Now;
                    objasmgcsjzm.imslsh = igcsjds;// i + 1;//秒数流水号
                    objasmgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjds).ToString("yyyy-MM-dd HH:mm:ss");

                    taskgcsj = taskgcsj.ContinueWith(tgcsj =>
                    {
                        for (int b = 0; b < 3; b++)
                        {
                            if (!bjiancestart)
                                return;
                            if (m_mainform.objbass.zmgcsjasm(businessId, objasmgcsjzm) == "1")
                            {
                                //izsj++;
                                break;
                            }
                            else
                            {
                                sxianshineirong = string.Format("过程数据联网失败。");
                                xianshixinxi();
                                string sshanghang = string.Format("过程数据联网失败");
                                string sxiahang = string.Format("");
                                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                                Thread.Sleep(200);
                                //return 4;
                            }
                        }
                    });
                    if (m_mainform.sfOBD)
                    {
                        int iobdgcdsd = igcsjds;
                        taskgcsj = taskgcsj.ContinueWith(tobd =>
                        {
                            if (!bjiancestart)
                                return;
                            if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(iobdgcdsd).ToString("yyyy-MM-dd HH:mm:ss"), iobdgcdsd) == "1")
                            {
                                //iobdds++;
                            }
                            else
                            {
                                sxianshineirong = string.Format("OBD过程数据联网失败。");
                                xianshixinxi();
                                string sshanghang = string.Format("OBD过程数据");
                                string sxiahang = string.Format("联网失败");
                                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                                Thread.Sleep(200);
                                //return 4;
                            }
                        });
                    }
                    break;
                }
            }


            if (m_fspeed < 38 || m_fspeed > 42)
            {

                //if (sASMzs.Contains("是"))
                //{

                if (icccs > 2)
                {
                    i = 0;
                    sxianshineirong = string.Format("{1}还剩{0}秒", gcsj - i, ilch == 1 ? "稳定时间" : "2540");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "2540", m_fspeed);
                        string sxiahang = string.Format("还剩{0}秒", gcsj - i);
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    itime = gcsj - i;
                    xianshitime();
                    if ((gcsj == 90) && (gcsj - i < 80))
                    {
                        sxianshineirong = "速度超范围，退出检测";
                        xianshixinxi();
                        return 6;
                    }
                    return 2;
                }
                icccs++;
                if (iljcccs > 5)
                {
                    i = 0;
                    iljcccs = 0;
                    sxianshineirong = string.Format("{1}还剩{0}秒", gcsj - i, ilch == 1 ? "稳定时间" : "2540");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("{0}速度{1}", ilch == 1 ? "稳定时间" : "2540", m_fspeed);
                        string sxiahang = string.Format("还剩{0}秒", gcsj - i);
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    itime = gcsj - i;
                    xianshitime();
                    if ((gcsj == 90) && (gcsj - i < 80))
                    {
                        sxianshineirong = "速度超范围，退出检测";
                        xianshixinxi();
                        return 6;
                    }
                    return 2;
                }
                iljcccs++;
                //}
                //else
                //{
                //    if (i > 0)
                //    {
                //        i--;
                //    }
                //    else
                //    {
                //        i = 0;
                //    }
                //}

            }
            else
            {
                icccs = 0;
            }
            int iyysj = (int)(DateTime.Now - dstart40).TotalMilliseconds;
            if (iyysj < 900)
            {
                Thread.Sleep(900 - iyysj);
            }
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);

            xianshiyibiao40();

            return 1;
        }


        /// <summary>
        /// 加速过程
        /// </summary>
        /// <param name="i">倒数第几秒</param>
        /// <param name="fForce25">输出多少力</param>
        /// <param name="ilch">1：稳定时间5秒。2：正常流程90秒</param>
        /// <param name="izsj">总时间</param>
        /// <param name="GKLX">工况类型</param>
        /// <param name="gcsj">过程时间，稳定为5，流程为90</param>
        /// <returns>1:正常2:重回90秒3:异常退出流程4:云景过程数据上传不上，重新过这一秒的数据</returns>
        public int jiasuguocheng(string GKLX)
        {
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
            m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
            if (rbOBDZS.Checked)
            {
                int ifdjzs = 0;
                int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                itrun = ifdjzs;
            }
            else
            {
                itrun = m_mainform.objzsy.m_iGasturn;
            }
            if (itrun < 500 || itrun > 5000)
            {
                sxianshineirong = "转速异常，退出检测";
                xianshixinxi();
                return 5;
            }

            float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iASMtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iASMtdz]);
            float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iASMtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iASMtdy]);
            float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iASMtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iASMtdh]);

            fForce = fzou + fyou + fhou;


            //上传实时过程数据
            model.ASM.ASMgcsjZM objasmgcsjzm = new model.ASM.ASMgcsjZM();
            //model.ASM.ASMgcsjZM objasmgcsj = new model.ASM.ASMgcsjZM();
            objasmgcsjzm.businessId = businessId;
            objasmgcsjzm.lineCode = m_mainform.lineCode;
            objasmgcsjzm.jcgcdysj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //objasmgcsjzm.imslsh = igcds++;// 90 + i + 1;
            objasmgcsjzm.m_SpeedGCSJ = m_fspeed;
            objasmgcsjzm.m_TrunGCSJ = itrun;
            objasmgcsjzm.m_PWGCSJ = (float)Math.Round((fForce * m_fspeed) / 360, 0);
            objasmgcsjzm.m_HCGCSJ = m_mainform.objfqy.m_iHc;
            objasmgcsjzm.m_COGCSJ = m_mainform.objfqy.m_fCo;
            objasmgcsjzm.m_CO2GCSJ = m_mainform.objfqy.m_fCo2;
            objasmgcsjzm.m_NOGCSJ = m_mainform.objfqy.m_iNo;
            objasmgcsjzm.m_O2GCSJ = m_mainform.objfqy.m_fO2;
            objasmgcsjzm.m_HCGCSJxz = (int)(getDF() * ((float)m_mainform.objfqy.m_iHc));
            objasmgcsjzm.m_COGCSJxz = (float)(getDF() * ((float)m_mainform.objfqy.m_fCo));
            objasmgcsjzm.m_CO2GCSJ = m_mainform.objfqy.m_fCo2;//问题，修正公式
            objasmgcsjzm.m_NOGCSJxz = (float)(getKH() * getDF() * (double)m_mainform.objfqy.m_iNo);
            objasmgcsjzm.m_O2GCSJ = m_mainform.objfqy.m_fO2;//问题，修正公式
            objasmgcsjzm.m_LAMDAGCSJ = m_mainform.objfqy.m_fLamda;
            objasmgcsjzm.m_DFGCSJ = (float)getDF();
            objasmgcsjzm.m_KHGCSJ = (float)getKH();
            objasmgcsjzm.m_lljqy = 0;//问题，                
            objasmgcsjzm.m_lljwd = 0;//问题，
            objasmgcsjzm.swendu = m_mainform.objfqy.m_fWenDu;
            objasmgcsjzm.sdaqiyi = m_mainform.objfqy.m_fYaLi;
            objasmgcsjzm.sshidu = m_mainform.objfqy.m_fShiDu;
            objasmgcsjzm.m_NLGCSJ = fForce;
            objasmgcsjzm.m_nlxzxs = 1;
            objasmgcsjzm.m_nlxs = 1;
            objasmgcsjzm.m_fyw = byw ? fywrg : m_mainform.objfqy.m_fyw;//油温

            objasmgcsjzm.m_WeightHC = m_mainform.objfqy.m_iHc * 130 / 224;
            objasmgcsjzm.m_WeightCO = m_mainform.objfqy.m_fCo * 280 / 224;
            objasmgcsjzm.m_WeightNO = m_mainform.objfqy.m_iNo * 300 / 224;
            objasmgcsjzm.m_ActPower = (float)Math.Round((fForce * m_fspeed) / 360, 0);

            objasmgcsjzm.GKLX = GKLX;//工况过程类型

            //if (sASMllgd.Contains("是"))// && i > 7)
            //{
            //    if (diliulangyujing(m_mainform.objfqy.m_fCo + m_mainform.objfqy.m_fCo2))
            //    {
            //        return 3;
            //    }
            //}

            //ddatagcsj = DateTime.Now;
            objasmgcsjzm.imslsh = igcsjds;// i + 1;//秒数流水号
            objasmgcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjds).ToString("yyyy-MM-dd HH:mm:ss");

            taskgcsj = taskgcsj.ContinueWith(tgcsj =>
            {
                for (int b = 0; b < 3; b++)
                {
                    if (!bjiancestart)
                        return;
                    if (m_mainform.objbass.zmgcsjasm(businessId, objasmgcsjzm) == "1")
                    {
                        //izsj++;
                        break;
                    }
                    else
                    {
                        sxianshineirong = string.Format("过程数据联网失败。");
                        xianshixinxi();
                        string sshanghang = string.Format("过程数据联网失败");
                        string sxiahang = string.Format("");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        Thread.Sleep(200);
                        //return 4;
                    }
                }
            });
            if (m_mainform.sfOBD)
            {
                int iobdgcdsd = igcsjds;
                taskgcsj = taskgcsj.ContinueWith(tobd =>
                {
                    if (!bjiancestart)
                        return;
                    if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(iobdgcdsd).ToString("yyyy-MM-dd HH:mm:ss"), iobdgcdsd) == "1")
                    {
                        //iobdds++;
                    }
                    else
                    {
                        sxianshineirong = string.Format("OBD过程数据联网失败。");
                        xianshixinxi();
                        string sshanghang = string.Format("OBD过程数据");
                        string sxiahang = string.Format("联网失败");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                        Thread.Sleep(200);
                        //return 4;
                    }
                });
            }

            return 1;
        }

        /// <summary>
        /// 判定过程2540
        /// </summary>
        /// <param name="i"></param>
        /// <param name="bksjc"></param>
        /// <param name="izjsj"></param>
        /// <returns>1：当次数据合格2：当次数据不合格0：快速检测合格3：超过限值5倍</returns>
        public int pd2540(int i, bool bksjc, int izjsj)
        {
            //判断快速10秒是否合格 第15秒到第25秒数据是否合格
            if (i == 19 && bksjc)
            {

                lamda40 = 0;
                ASMType = "3";
                //结果修正
                double dhc40 = 0;
                double dno40 = 0;
                double dco40 = 0;

                for (int j = izjsj - 9; j <= izjsj; j++)
                {
                    dhc40 = dhc40 + m_HCGCSJ40xz[j];// *m_DFGCSJ40[j];
                    dno40 = dno40 + m_NOGCSJ40xz[j];// *m_DFGCSJ40[j] * m_KHGCSJ40[j];
                    dco40 = dco40 + m_COGCSJ40xz[j];// *m_DFGCSJ40[j];
                    lamda40 = lamda40 + m_LAMDAGCSJ40[j];
                }
                iHC40 = (int)(dhc40 / 10);
                iNO40 = (int)(dno40 / 10);
                fCO40 = (float)(dco40 / 10);
                lamda40 = lamda40 / 10;


                fdjzs2540 = itrun;//发动机转速
                fdjyw2540 = byw ? fywrg : m_mainform.objfqy.m_fyw;//油温

                if (iHC40 < iHCXZ40 * 0.5 && iNO40 < iNOXZ40 * 0.5 && fCO40 < fCOXZ40 * 0.5)//test
                {
                    m_mainform.objbass.GetPic("24");//安车拍照发送命令
                    m_mainform.objbass.GetPic("124");
                    m_mainform.objbass.GetPic("224");
                    sxianshineirong = string.Format("快速检测合格检测结束");
                    xianshixinxi();

                    {
                        string sshanghang = string.Format("快速检测合格");
                        string sxiahang = string.Format("检测结束");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    //fwj20200222
                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER5025={0},
                                                HCER5025={1},
                                                NOER5025={2},
                                                Gasturn25={3},
                                                A_QR25={4},
                                                Lamda25={5},
                                                GasWenDu={6},
                                                GasShiDu={7},
                                                GasYaLi={8},
                                                Time_begin='{9}',
                                                Time_end='{10}' ,
                                                WQPD={11} 
                                                where DETECT_ID={12} or ASM_JYLSH='{13}'  ",
                                  fCO40,
                                  iHC40,
                                  iNO40,
                                  m_TrunGCSJ40[0],
                                  1,
                                  m_LAMDAGCSJ40[0],
                                  fwendu,
                                  fshidu,
                                  fdaqiya,
                                  timeStart,
                                  timeEnd,
                                  1,
                                  DETECT_ID,
                                  businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);//

                    return 0;
                }

                if (iHC40 > iHCXZ40 || iNO40 > iNOXZ40 || fCO40 > fCOXZ40)
                {
                    m_mainform.objbass.GetPic("24");//安车拍照发送命令
                    m_mainform.objbass.GetPic("124");
                    m_mainform.objbass.GetPic("224");
                    bgood = false;
                    sxianshineirong = string.Format("检测不合格检测结束");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("检测不合格");
                        string sxiahang = string.Format("检测结束");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }

                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER2540={0},
                                                HCER2540={1},
                                                NOER2540={2},
                                                Gasturn40={3},
                                                Lamda40={4},
                                                Time_begin='{5}',
                                                Time_end='{6}',
                                                WQPD={7}
                                                where DETECT_ID={8} or ASM_JYLSH='{9}'  ",
                                  fCO40,
                                  iHC40,
                                  iNO40,
                                  m_TrunGCSJ40[0],
                                  m_LAMDAGCSJ40[0],
                                  timeStart,
                                  timeEnd,
                                  2,
                                  DETECT_ID,
                                  businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    return 2;
                }
            }
            else
            {
                if (m_mainform.sconnetname.Contains("安车") && i < 19)
                {
                    return 1;
                }
                ASMType = "4";
                //int j = 0;
                IsTenMCondition40 = 0;
                lamda40 = 0;
                double dhc40 = 0;
                double dno40 = 0;
                double dco40 = 0;

                for (int j = izjsj - 9; j <= izjsj; j++)
                {
                    dhc40 = dhc40 + m_HCGCSJ40xz[j];// * m_DFGCSJ40[j];
                    dno40 = dno40 + m_NOGCSJ40xz[j];// * m_DFGCSJ40[j]* m_KHGCSJ40[j];
                    dco40 = dco40 + m_COGCSJ40xz[j];// * m_DFGCSJ40[j] ;
                    lamda40 = lamda40 + m_LAMDAGCSJ40[j];
                }
                iHC40 = (int)(dhc40 / 10);
                iNO40 = (int)(dno40 / 10);
                fCO40 = (float)(dco40 / 10);
                lamda40 = lamda25 / 10;

                if (iHC40 > iHCXZ40 || iNO40 > iNOXZ40 || fCO40 > fCOXZ40)
                {
                    m_mainform.objbass.GetPic("24");//安车拍照发送命令
                    m_mainform.objbass.GetPic("124");
                    m_mainform.objbass.GetPic("224");
                    bgood = false;
                    sxianshineirong = string.Format("检测不合格检测结束");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("检测不合格");
                        string sxiahang = string.Format("检测结束");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }

                    timeEnd = DateTime.Now.ToLocalTime().ToString();
                    string sql = string.Format(@"update Detects_SJE set 
                                                COER2540={0},
                                                HCER2540={1},
                                                NOER2540={2},
                                                Gasturn40={3},
                                                Lamda40={4},
                                                Time_begin='{5}',
                                                Time_end='{6}',
                                                WQPD={7}
                                                where DETECT_ID={8} or ASM_JYLSH='{9}'  ",
                                  fCO40,
                                  iHC40,
                                  iNO40,
                                  m_TrunGCSJ40[0],
                                  m_LAMDAGCSJ40[0],
                                  timeStart,
                                  timeEnd,
                                  2,
                                  DETECT_ID,
                                  businessId);
                    m_mainform.objbass.objdb.InsertDB(sql);

                    return 2;
                }
            }
            return 1;

          
        }
        public bool PowerToSpeed(float fSpeed, float fPower, int dTime)
        {

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\ASM工况力码值.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            string smz = ReadValue("设置", fSpeed.ToString() + ((int)fPower).ToString());
            int imz = 0;
            int.TryParse(smz, out imz);
            //if (imz > 500)
            //    shuchu = imz;


            float fF = 360 * fPower / fSpeed;
            int ibujing = 20;
            DateTime dstartds = DateTime.Now;
            DateTime dupload = DateTime.Now;
            while(true)
            {

                if (m_mainform.DateDiff(DateTime.Now, dupload) > 1000)
                {
                    dupload = DateTime.Now;
                    string sgklx = "4";
                    if (fSpeed == 25)
                    {
                        sgklx = "1";
                    }
                    else
                    {
                        sgklx = "4";
                    }
                    int ireturn = jiasuguocheng(sgklx);//(i, fForce40, 1, 0, "4", 5);//1:正常2:重回90秒3:异常退出流程4:云景过程数据上传不上，重新过这一秒的数据
                    if (ireturn != 4)
                    {
                        igcsjds++;
                    }
                    if (ireturn == 5)
                    {
                        return false;
                    }
                    //
                }
                if (m_mainform.DateDiff(DateTime.Now, dstartds) > 1000 * 10)
                {
                    break; //
                }
                Thread.Sleep(200);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iASMtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iASMtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iASMtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;

                if (fSpeed < 30)
                {
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                    xianshiyibiao();

                }
                else
                {
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                    xianshiyibiao40();

                }

                {
                    string sshanghang = string.Format("目标速度{0}", fSpeed);
                    string sxiahang = string.Format("当前速度{0}", m_fspeed);
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                if (m_fspeed < 10)
                {
                    dstartds = DateTime.Now;

                }
                if (m_fspeed > 15)
                {
                    if (fForce > fF - 20 && fForce < fF + 50)
                    {
                        path = System.Windows.Forms.Application.StartupPath + "\\ASM工况力码值.ini";
                        path1 = string.Format(@"{0}", path);
                        Ini(path1);
                        Writue("设置", fSpeed.ToString() + ((int)fPower).ToString(), shuchu.ToString());
                        break;
                    }
                    else if (fForce < fF)
                    {
                        if (m_fspeed > 15)
                        {
                            m_mainform.DAC.PutVol(shuchu);
                            Thread.Sleep(300);
                            shuchu = shuchu + ibujing;
                        }
                    }
                    else if (fForce > fF + 50)
                    {
                        if (m_fspeed > 15)
                        {
                            shuchu = shuchu - ibujing;
                            m_mainform.DAC.PutVol(shuchu);
                            Thread.Sleep(300);

                        }
                    }
                }
                else
                {
                    m_mainform.DAC.PutVol(800);
                }

                Thread.Sleep(100);
            }



            return true;
        }

        private void TESTASM_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }

        private void kaishijiance_Click(object sender, EventArgs e)
        {
           
        }
        public double floTodou(float m_float)
        {
             double m_dou=0;
             double.TryParse(string.Format("{0}", m_float), out m_dou);
             return m_dou;
        }
        public double intTodou(int m_float)
        {
            double m_dou = 0;
            double.TryParse(string.Format("{0}", m_float), out m_dou);
            return m_dou;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(false);
        }
        Random ran = new Random();
        public int getRandom(int imin,int imax)
        {       
            return ran.Next(imin, imax);
        }

        private void zhongzhijiance_Click(object sender, EventArgs e)
        {
            ASM_Stop = true;
            this.Close();

        }
        public bool diliulangyujing(float fcoco2)
        {
            if (fcoco2 < 6)
            {
                xinxixianshi.ForeColor = Color.Red;
                sxianshineirong = string.Format("采样探头已掉落!!!");
                xianshixinxi();
                {
                    string sshanghang = string.Format("采样探头已掉落");
                    string sxiahang = string.Format("停止检测请减速");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                Thread.Sleep(3000);
                sxianshineirong = string.Format("停止检测请减速");
                xianshixinxi();
                {
                    string sshanghang = string.Format("采样探头已掉落");
                    string sxiahang = string.Format("停止检测请减速");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                for (; ; )
                {
                    if (m_fspeed < 1)
                    {
                        break;
                    }
                }

                return true;
            }

            m_mainform.objfqy.m_fDLLYJ = false;
            //if (m_mainform.SendDeviceCmdGas(0x61, 0x9A))
            if (m_mainform.objfqy.SendDeviceCmd(6))
            {
                Thread.Sleep(500);
                if (m_mainform.objfqy.m_fDLLYJ)
                {
                    xinxixianshi.ForeColor = Color.Red;
                    sxianshineirong = string.Format("管道堵塞，流量过低");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("管道堵塞流量过低");
                        string sxiahang = string.Format("停止检测请减速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    Thread.Sleep(3000);
                    sxianshineirong = string.Format("停止检测请减速");
                    xianshixinxi();
                    {
                        string sshanghang = string.Format("管道堵塞流量过低");
                        string sxiahang = string.Format("停止检测请减速");
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    for (; ; )
                    {
                        if (m_fspeed < 1)
                        {
                            break;
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }

            {
                return false;
            }
        }
        private void TESTASM_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (ASM_Start)
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();

                t2.Abort();
                t2.DisableComObjectEagerCleanup();

                t3.Abort();
                t3.DisableComObjectEagerCleanup();
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (m_mainform.DateDiff(DateTime.Now, dtl) > itlsj * 1000)
            {
                xinxixianshi.Text = string.Format("调零结束请插入采样探头");
                //skinBut_ksjc.Enabled = true;
                threadzj = new Thread(zijian);
                threadzj.Start();
                timer1.Enabled = false;

            }
        }
        Thread threadzj;
        bool bzijian = true;
        public void zijian()
        {
            m_mainform.objfqy.SendDeviceCmd(26);//
            sxianshineirong = string.Format(@"正在检测环境空气");
            xianshixinxi();//---------
            {
                string sshanghang = string.Format("正在检测环境空气");
                string sxiahang = "";
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            }
            Thread.Sleep(2000);
            DateTime dtime = DateTime.Now;
            while (true)
            {
                if (!bzijian)
                {
                    m_mainform.objfqy.SendDeviceCmd(24);//
                    MethodInvoker ln = new MethodInvoker(setkaishi);
                    this.BeginInvoke(ln);
                    return;
                }
                m_mainform.objfqy.SendDeviceCmd(3);//
                Thread.Sleep(300);
                sxianshineirong = string.Format(@"HC:{0}。CO:{1}。NO:{2}。", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                xianshixinxi();//
                {
                    string sshanghang = string.Format("HC{0}CO{1}NO{2}", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                    string sxiahang = "";
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                }
                //Thread.Sleep(2000);

                if (dtime.AddSeconds(15) < DateTime.Now)
                {
                    break;
                }
            }
            Thread.Sleep(1000);
            m_mainform.objfqy.SendDeviceCmd(24);//
            sxianshineirong = string.Format(@"环境空气检测完成");
            xianshixinxi();//
            {
                string sshanghang = string.Format("环境空气检测完成");
                string sxiahang = "";
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            }
            Thread.Sleep(2000);
            sxianshineirong = string.Format(@"正在检测背景空气");
            xianshixinxi();//
            {
                string sshanghang = string.Format("正在检测背景空气");
                string sxiahang = "";
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            }
            Thread.Sleep(1000);
            m_mainform.objfqy.SendDeviceCmd(25);//dtime = DateTime.Now;
            dtime = DateTime.Now;
            while (true)
            {
                if (!bzijian)
                {
                    m_mainform.objfqy.SendDeviceCmd(24);//
                    MethodInvoker ln = new MethodInvoker(setkaishi);
                    this.BeginInvoke(ln);
                    return;
                }
                m_mainform.objfqy.SendDeviceCmd(3);//
                Thread.Sleep(300);
                sxianshineirong = string.Format(@"HC:{0}。CO:{1}。NO:{2}。", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                xianshixinxi();//
                bool bpd = true;
                if (m_mainform.objfqy.m_iHc > 7 || m_mainform.objfqy.m_fCo >= 0.02 || m_mainform.objfqy.m_iNo >= 5)
                {
                    {
                        string sshanghang = string.Format("HC{0}CO{1}NO{2}", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                        string sxiahang = "背景空气检测不合格";
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                    Thread.Sleep(2000);
                    sxianshineirong = string.Format(@"背景空气检测不合格");
                    xianshixinxi();//
                    bpd = false;
                    Thread.Sleep(2000);
                }
                else
                {
                    {
                        string sshanghang = string.Format("HC{0}CO{1}NO{2}", m_mainform.objfqy.m_iHc, m_mainform.objfqy.m_fCo.ToString("0.00"), m_mainform.objfqy.m_iNo);
                        string sxiahang = "";
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    }
                }
                if (bpd && dtime.AddSeconds(14) < DateTime.Now)
                {
                    break;
                }
            }
            //Thread.Sleep(1000);
            //m_mainform.objfqy.SendDeviceCmd(2);//
            Thread.Sleep(1000);
            m_mainform.objfqy.SendDeviceCmd(24);//
            sxianshineirong = string.Format(@"背景空气合格");
            xianshixinxi();//
            {
                string sshanghang = string.Format("背景空气合格");
                string sxiahang = "";
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            }
            Thread.Sleep(2000);
            MethodInvoker lnex = new MethodInvoker(setkaishi);
            this.BeginInvoke(lnex);
        }
        public void setkaishi()
        {
            skinBut_ksjc.Enabled = true;
        }

        private void but_shezhi_Click(object sender, EventArgs e)
        {
            ASMPeiZhi obj = new ASMPeiZhi();
            obj.ShowDialog();
        }

        bool bjiancestart = false;
        private void skinBut_ksjc_Click(object sender, EventArgs e)
        {
            if (srllx.Contains("3"))
            {
                if (MessageBox.Show("该车是否双燃料？", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    srllx = "1";
                }
            }

            bjiancestart = true;
            bdushu = true;
            m_mainform.DAC.PutVol(0);
            m_mainform.objfqy.SendDeviceCmd(3);
            model.尾气自检.检测前自检.ziasm objzj = new model.尾气自检.检测前自检.ziasm();

            objzj.dtBeginTime = DateTime.Now.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.dtEndTime = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.nCheckResult = "1";
            objzj.fEnvTemperature = m_mainform.objfqy.m_fWenDu.ToString();
            objzj.fEnvHumidity = m_mainform.objfqy.m_fShiDu.ToString();
            objzj.fEnvPressure = m_mainform.objfqy.m_fYaLi.ToString();
            objzj.nEnvTemperatureOK = "1";
            objzj.nEnvHumidityOK = "1";
            objzj.nEnvPressureOK = "1";
            objzj.dtZeroBeginTime = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.dtZeroEndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            objzj.fEnviHC = "0";
            objzj.fEnviCO = "0";
            objzj.fEnviNOx = "0";
            objzj.nEnviCheckOK = "1";
            objzj.fGasHC = "0";
            objzj.fGasCO = "0";
            objzj.fGasNOx = "0";
            objzj.fGasCheckOK = "1";
            objzj.nFlowCheckOK = "1";
            m_mainform.objbass.jianceqianzj(businessId, objzj);

            t3 = new Thread(new ThreadStart(Thread3));
            t3.Priority = ThreadPriority.Lowest;
            t3.Start();

            m_mainform.objbass.BgAirHC();//HC上传
            if (m_mainform.objbass.start(businessId, "", "", "", bobdhg) == "0")
                return;

            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq");//智慧
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh");//智慧
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaozhong, "wqqj");//智慧

            objasmsj = new model.ASM.ASMsj();
            objasmgcsj = new model.ASM.ASMgcsj();
            skinBut_ksjc.Enabled = false;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();

            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.Lowest;
            t2.Start();


            //t3 = new Thread(new ThreadStart(Thread3));
            //t3.Priority = ThreadPriority.Lowest;
            //xswq.ShowDialog();
        }

        private void skinBut_zjjc_Click(object sender, EventArgs e)
        {
            bjiancestart = false;
            控制流程.flowcrtl.iquanjuzhuangtai = 0;
            m_mainform.DAC.PutVol(0);
            m_mainform.objfqy.bfqyco2 = false;
            ASM_Stop = true;
            //t3.Abort();
            //t3.DisableComObjectEagerCleanup();
            Thread.Sleep(1500);
            m_mainform.objfqy.SendDeviceCmd(2);//停止测量
            Thread.Sleep(1500);
            m_mainform.objfqy.SendDeviceCmd(4);//反吹
            try
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();
            }
            catch (Exception ex) { }
            try
            {
                t2.Abort();
                t2.DisableComObjectEagerCleanup();
            }
            catch (Exception ex) { }
            try
            {
                t3.Abort();
                t3.DisableComObjectEagerCleanup();
            }
            catch (Exception ex) { }
            try
            {
                threadzj.Abort();
                threadzj.DisableComObjectEagerCleanup();
            }
            catch (Exception ex) { }

            this.Close();
        }

        private void skinBut_jssq_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void skinBut_jsxj_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(false);
        }

        private void skinBut_sz_Click(object sender, EventArgs e)
        {
            ASMPeiZhi obj = new ASMPeiZhi();
            obj.ShowDialog();
        }

      
        public void WriteGraphEX(ZedGraphControl zgc, string[] izdz, string[] izdy, int icount)
        {
            double imax = 50;
           

            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, Color.Aqua, 45.0f);
            myPane.Legend.Fill = new Fill(Color.Gainsboro);
            myPane.Chart.Fill = new Fill(Color.Gainsboro);

            myPane.CurveList.Clear();

            myPane.Title.Text = string.Format("曲线");

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "速度(km/h)";

            myPane.YAxis.MajorGrid.IsVisible = false;
            myPane.YAxis.MinorTic.Size = 0f;

            myPane.YAxis.Scale.Min = 0;
            myPane.YAxis.Scale.Max = imax + 0;


            myPane.YAxis.Scale.MajorStep = 10;



            zgc.IsShowPointValues = true;//数据节点
            string ss0 = string.Format("速度");
            string ss1 = string.Format("功率");

            PointPairList list0 = new PointPairList();
            PointPairList list1 = new PointPairList();


            LineItem myCurve0 = myPane.AddCurve(ss0, list0, Color.Blue,
                                    SymbolType.None);
            LineItem myCurve1 = myPane.AddCurve(ss1, list1, Color.Red,
                                    SymbolType.None);
            myCurve0.Line.Width = 1.7F;
            myCurve1.Line.Width = 1.7F;

            for (int i = 0; i < icount; i++)
            {
                double dx = 0;
                double dy = 0;
                double.TryParse(izdz[i], out dx);
                double.TryParse(izdy[i], out dy);
                list0.Add(i, dx);
                list1.Add(i, dy);
            }
            zgc.AxisChange();
            zgc.Invalidate();
        }
        //记录ASM过程数据
        public void baocunGCSJ_ASM(string sjylsh, string stime)
        {
            string glkqxs = "";
            //过程数据
            string cysx = "";
            string hcclz = "";
            string noclz = "";
            string cs = "";
            string zs = "";
            string coclz = "";
            string co2clz = "";
            string o2clz = "";
            string xsxzxs = "";
            string sdxzxs = "";
            string jsgl = "";
            string zsgl = "";
            string jzgl = "";
            string hjwd = "";
            string dqyl = "";
            string xdsd = "";
            string yw = "";
            string sjxl = "";
            string nl = "";
            string scfz = "";
            string jczt = "";

            string hcxzz = "";
            string noxzz = "";
            string coxzz = "";

            #region 数据过程数据
            for (int i = 0; i < count5025 + 1; i++)
            {
                if (i == 0)
                {
                    cysx = string.Format(@"{0}", i + 1);
                    hcclz = string.Format(@"{0}", m_HCGCSJ25[i]);
                    noclz = string.Format(@"{0}", m_NOGCSJ25[i]);
                    cs = string.Format(@"{0}", m_SpeedGCSJ25[i].ToString("0.00"));
                    zs = string.Format(@"{0}", m_TrunGCSJ25[i]);
                    coclz = string.Format(@"{0}", m_COGCSJ25[i]);
                    co2clz = string.Format(@"{0}", m_CO2GCSJ25[i]);
                    o2clz = string.Format(@"{0}", m_O2GCSJ25[i]);

                    xsxzxs = string.Format(@"{0}", m_DFGCSJ25[i].ToString("0.000")); ;
                    sdxzxs = string.Format(@"{0}", m_KHGCSJ25[i].ToString("0.000"));
                    jsgl = string.Format(@"{0}", 0.5f);
                    zsgl = string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    jzgl = string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    hjwd = string.Format(@"{0}", swendu25[i]);
                    dqyl = string.Format(@"{0}", sdaqiyi25[i]);
                    xdsd = string.Format(@"{0}", sshidu25[i]);
                    yw = string.Format(@"{0}", syouwen25[i]);
                    glkqxs = string.Format(@"{0}", m_LAMDAGCSJ25[i]);

                    sjxl = string.Format(@"{0}", m_ProcessTime25[i].Length < 1 ? m_ProcessTime25[1] : m_ProcessTime25[i]);
                    nl = string.Format(@"{0}", m_NLGCSJ25[i]);
                    scfz = string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    //jczt = string.Format(@"{0}", m_jcztGCSJ25[i]);
                    jczt = "2";

                    hcxzz = string.Format(@"{0}", m_HCGCSJ25xz[i]);
                    noxzz = string.Format(@"{0}", m_NOGCSJ25xz[i]);
                    coxzz = string.Format(@"{0}", m_COGCSJ25xz[i]);
                }
                else
                {
                    cysx = cysx + "," + string.Format(@"{0}", i + 1);
                    hcclz = hcclz + "," + string.Format(@"{0}", m_HCGCSJ25[i]);
                    noclz = noclz + "," + string.Format(@"{0}", m_NOGCSJ25[i]);
                    cs = cs + "," + string.Format(@"{0}", m_SpeedGCSJ25[i].ToString("0.00"));
                    zs = zs + "," + string.Format(@"{0}", m_TrunGCSJ25[i]);
                    coclz = coclz + "," + string.Format(@"{0}", m_COGCSJ25[i]);
                    co2clz = co2clz + "," + string.Format(@"{0}", m_CO2GCSJ25[i]);
                    o2clz = o2clz + "," + string.Format(@"{0}", m_O2GCSJ25[i]);

                    xsxzxs = xsxzxs + "," + string.Format(@"{0}", m_DFGCSJ25[i].ToString("0.000")); ;
                    sdxzxs = sdxzxs + "," + string.Format(@"{0}", m_KHGCSJ25[i].ToString("0.000"));
                    jsgl = jsgl + "," + string.Format(@"{0}", 0.5f);
                    zsgl = zsgl + "," + string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    jzgl = jzgl + "," + string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    hjwd = hjwd + "," + string.Format(@"{0}", swendu25[i]);
                    dqyl = dqyl + "," + string.Format(@"{0}", sdaqiyi25[i]);
                    xdsd = xdsd + "," + string.Format(@"{0}", sshidu25[i]);
                    yw = yw + "," + string.Format(@"{0}", syouwen25[i]);
                    glkqxs = glkqxs + "," + string.Format(@"{0}", m_LAMDAGCSJ25[i]);

                    sjxl = sjxl + "," + string.Format(@"{0}", m_ProcessTime25[i]);
                    nl = nl + "," + string.Format(@"{0}", m_NLGCSJ25[i]);
                    scfz = scfz + "," + string.Format(@"{0}", m_PWGCSJ25[i].ToString("0.00"));
                    if (i > 9 && i < 20)
                    {
                        jczt = jczt + "," + "1";
                    }
                    else
                    {
                        jczt = jczt + "," + "2";
                    }
                    //jczt = jczt + "," + string.Format(@"{0}", m_jcztGCSJ25[i]);
                    hcxzz = hcxzz + "," + string.Format(@"{0}", m_HCGCSJ25xz[i]);
                    noxzz = noxzz + "," + string.Format(@"{0}", m_NOGCSJ25xz[i]);
                    coxzz = coxzz + "," + string.Format(@"{0}", m_COGCSJ25xz[i]);


                }


            }

            //保存曲线数据

            if (b2540)
            {
                for (int i = 0; i < count2540 + 1; i++)
                {

                    cysx = cysx + "," + string.Format(@"{0}", count5025 + i + 1);
                    hcclz = hcclz + "," + string.Format(@"{0}", m_HCGCSJ40[i]);
                    noclz = noclz + "," + string.Format(@"{0}", m_NOGCSJ40[i]);
                    cs = cs + "," + string.Format(@"{0}", m_SpeedGCSJ40[i].ToString("0.00"));
                    zs = zs + "," + string.Format(@"{0}", m_TrunGCSJ40[i]);
                    coclz = coclz + "," + string.Format(@"{0}", m_COGCSJ40[i]);
                    co2clz = co2clz + "," + string.Format(@"{0}", m_CO2GCSJ40[i]);
                    o2clz = o2clz + "," + string.Format(@"{0}", m_O2GCSJC40[i]);

                    xsxzxs = xsxzxs + "," + string.Format(@"{0}", m_DFGCSJ40[i].ToString("0.000")); ;
                    sdxzxs = sdxzxs + "," + string.Format(@"{0}", m_KHGCSJ40[i].ToString("0.000"));
                    jsgl = jsgl + "," + string.Format(@"{0}", 0.5f);
                    zsgl = zsgl + "," + string.Format(@"{0}", m_PWGCSJ40[i].ToString("0.00"));
                    jzgl = jzgl + "," + string.Format(@"{0}", m_PWGCSJ40[i].ToString("0.00"));
                    hjwd = hjwd + "," + string.Format(@"{0}", swendu40[i]);
                    dqyl = dqyl + "," + string.Format(@"{0}", sdaqiyi40[i]);
                    xdsd = xdsd + "," + string.Format(@"{0}", sshidu40[i]);
                    yw = yw + "," + string.Format(@"{0}", syouwen40[i]);
                    glkqxs = glkqxs + "," + string.Format(@"{0}", m_LAMDAGCSJ40[i]);

                    sjxl = sjxl + "," + string.Format(@"{0}", m_ProcessTime40[i]);
                    nl = nl + "," + string.Format(@"{0}", m_NLGCSJ40[i]);
                    scfz = scfz + "," + string.Format(@"{0}", m_PWGCSJ40[i].ToString("0.00"));
                    //jczt = jczt + "," + string.Format(@"{0}", m_jcztGCSJ40[i]);
                    //if (i > count2540 - 10)
                    if (i > 9 && i < 20)
                    {
                        jczt = jczt + "," + "3";
                    }
                    {
                        jczt = jczt + "," + "4";
                    }

                    hcxzz = hcxzz + "," + string.Format(@"{0}", m_HCGCSJ40xz[i]);
                    noxzz = noxzz + "," + string.Format(@"{0}", m_NOGCSJ40xz[i]);
                    coxzz = coxzz + "," + string.Format(@"{0}", m_COGCSJ40xz[i]);

                }

            }
            ///保存数据库中
            string sql;
            sql = string.Format(@"Select *  from GCSJ_ASM where jylsh='{0}' and  time='{1}'", sjylsh, stime);
            DataTable dt = m_mainform.objbass.objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update GCSJ_ASM  set GCSJ_ASM_hcclz='{0}'
                                                              ,GCSJ_ASM_zs='{1}'
                                                              ,GCSJ_ASM_coclz='{2}'
                                                              ,GCSJ_ASM_glkqxs='{3}'
                                                              ,GCSJ_ASM_yw='{4}'
                                                              ,GCSJ_ASM_co2clz='{5}'
                                                              ,GCSJ_ASM_o2clz='{6}'
                                                              ,GCSJ_ASM_hjwd='{7}'
                                                              ,GCSJ_ASM_dqyl='{8}'
                                                              ,GCSJ_ASM_xdsd='{9}'
                                                              ,GCSJ_ASM_sjxl='{10}'
                                                              ,GCSJ_ASM_noclz='{11}'
                                                              ,GCSJ_ASM_cs='{12}'
                                                              ,GCSJ_ASM_xsxzxs='{13}'
                                                              ,GCSJ_ASM_sdxzxs='{14}'
                                                              ,GCSJ_ASM_jsgl='{15}'
                                                              ,GCSJ_ASM_zsgl='{16}'
                                                              ,jczt  ='{19}'
                                                              ,hcxzz ='{20}'
                                                              ,noxzz ='{21}'
                                                              ,coxzz ='{22}'
                                                        where jylsh='{17}' and  time='{18}' ",
                                                                hcclz,
                                                                zs,
                                                                coclz,
                                                                glkqxs,
                                                                yw,
                                                                co2clz,
                                                                o2clz,
                                                                hjwd,
                                                                dqyl,
                                                                xdsd,
                                                                sjxl,
                                                                noclz,
                                                                cs,
                                                                xsxzxs,
                                                                sdxzxs,
                                                                jzgl,
                                                                jsgl,
                                                                sjylsh,
                                                                stime,
                                                                jczt,
                                                                hcxzz,
                                                                noxzz,
                                                                coxzz);


            }
            else
            {

                sql = string.Format(@"insert into GCSJ_ASM (
                                               jylsh
                                                ,time
                                                ,GCSJ_ASM_hcclz
                                              ,GCSJ_ASM_zs
                                              ,GCSJ_ASM_coclz
                                              ,GCSJ_ASM_glkqxs
                                              ,GCSJ_ASM_yw
                                              ,GCSJ_ASM_co2clz
                                              ,GCSJ_ASM_o2clz
                                              ,GCSJ_ASM_hjwd
                                              ,GCSJ_ASM_dqyl
                                              ,GCSJ_ASM_xdsd
                                              ,GCSJ_ASM_sjxl
                                              ,GCSJ_ASM_noclz
                                              ,GCSJ_ASM_cs
                                              ,GCSJ_ASM_xsxzxs
                                              ,GCSJ_ASM_sdxzxs
                                              ,GCSJ_ASM_jsgl
                                              ,GCSJ_ASM_zsgl,
                                              jczt,
                                              hcxzz,
                                              noxzz,
                                              coxzz) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}',
                                                '{9}',
                                                '{10}',
                                                '{11}',
                                                '{12}',
                                                '{13}',
                                                '{14}',
                                                '{15}',
                                                '{16}',
                                                '{17}',
                                                '{18}',
                                                '{19}',
                                                '{20}',
                                                '{21}',
                                                '{22}')",
                                                sjylsh,
                                                stime,
                                                hcclz,
                                                zs,
                                                coclz,
                                                glkqxs,
                                                yw,
                                                co2clz,
                                                o2clz,
                                                hjwd,
                                                dqyl,
                                                xdsd,
                                                sjxl,
                                                noclz,
                                                cs,
                                                xsxzxs,
                                                sdxzxs,
                                                jzgl,
                                                jsgl,
                                                 jczt,
                                                hcxzz,
                                                noxzz,
                                                coxzz);
            }
            m_mainform.objbass.objdb.InsertDB(sql);
            //
            #endregion


        }

        public void baocunGCSJ_OBD(string sjylsh)
        {
            string sobdgcsj_jqmkd = "";
            string sobdgcsj_fh = "";
            string sobdgcsj_qycgqxh = "";
            string sobdgcsj_glkqxs = "";
            string sobdgcsj_ymkd = "";
            string sobdgcsj_cs = "";
            string sobdgcsj_fdjzs = "";
            string sobdgcsj_jql = "";
            string sobdgcsj_jqyl = "";
            string sobdgcsj_scgl = "";
            string sobdgcsj_zyyl = "";
            string sobdgcsj_hyl = "";
            string sobdgcsj_no = "";
            string sobdgcsj_nsbsl = "";
            string sobdgcsj_pqwd = "";
            string sobdgcsj_klbjqyc = "";
            string sobdgcsj_egrkd = "";
            string sobdgcsj_rypsyl = "";
            string sobdgcsj_sj = "";
            for (int iz = 0; iz < objasmobds.ObdAirPressure.Length; iz++)
            {
                if (!string.IsNullOrWhiteSpace(objasmobds.obdjcsj[iz]))
                {
                    sobdgcsj_jqmkd = sobdgcsj_jqmkd + objasmobds.ObdThrottle[iz] + ",";
                    sobdgcsj_fh = sobdgcsj_fh + objasmobds.ObdCLV[iz] + ",";
                    sobdgcsj_qycgqxh = sobdgcsj_qycgqxh + objasmobds.ObdPreOxygen[iz] + ",";
                    sobdgcsj_glkqxs = sobdgcsj_glkqxs + objasmobds.ObdExcessAirFactor[iz] + ",";
                    sobdgcsj_ymkd = sobdgcsj_ymkd + "" + ",";
                    sobdgcsj_cs = sobdgcsj_cs + objasmobds.ObdSpeed[iz] + ",";
                    sobdgcsj_fdjzs = sobdgcsj_fdjzs + objasmobds.ObdRPM[iz] + ",";
                    sobdgcsj_jql = sobdgcsj_jql + objasmobds.ObdAirInput[iz] + ",";
                    sobdgcsj_jqyl = sobdgcsj_jqyl + objasmobds.ObdAirPressure[iz] + ",";
                    sobdgcsj_scgl = sobdgcsj_scgl + objasmobds.ObdPower[iz] + ",";
                    sobdgcsj_zyyl = sobdgcsj_zyyl + "" + ",";
                    sobdgcsj_hyl = sobdgcsj_hyl + "" + ",";
                    sobdgcsj_no = sobdgcsj_no + "" + ",";
                    sobdgcsj_nsbsl = sobdgcsj_nsbsl + "" + ",";
                    sobdgcsj_pqwd = sobdgcsj_pqwd + "" + ",";
                    sobdgcsj_klbjqyc = sobdgcsj_klbjqyc + "" + ",";
                    sobdgcsj_egrkd = sobdgcsj_egrkd + "" + ",";
                    sobdgcsj_rypsyl = sobdgcsj_rypsyl + "" + ",";
                    sobdgcsj_sj = sobdgcsj_sj + objasmobds.obdjcsj[iz] + ",";

                }
            }
            sobdgcsj_jqmkd = sobdgcsj_jqmkd.TrimEnd(',');
            sobdgcsj_fh = sobdgcsj_fh.TrimEnd(',');
            sobdgcsj_qycgqxh = sobdgcsj_qycgqxh.TrimEnd(',');
            sobdgcsj_glkqxs = sobdgcsj_glkqxs.TrimEnd(',');
            sobdgcsj_ymkd = sobdgcsj_ymkd.TrimEnd(',');
            sobdgcsj_cs = sobdgcsj_cs.TrimEnd(',');
            sobdgcsj_fdjzs = sobdgcsj_fdjzs.TrimEnd(',');
            sobdgcsj_jql = sobdgcsj_jql.TrimEnd(',');
            sobdgcsj_jqyl = sobdgcsj_jqyl.TrimEnd(',');
            sobdgcsj_scgl = sobdgcsj_scgl.TrimEnd(',');
            sobdgcsj_zyyl = sobdgcsj_zyyl.TrimEnd(',');
            sobdgcsj_hyl = sobdgcsj_hyl.TrimEnd(',');
            sobdgcsj_no = sobdgcsj_no.TrimEnd(',');
            sobdgcsj_nsbsl = sobdgcsj_nsbsl.TrimEnd(',');
            sobdgcsj_pqwd = sobdgcsj_pqwd.TrimEnd(',');
            sobdgcsj_klbjqyc = sobdgcsj_klbjqyc.TrimEnd(',');
            sobdgcsj_egrkd = sobdgcsj_egrkd.TrimEnd(',');
            sobdgcsj_rypsyl = sobdgcsj_rypsyl.TrimEnd(',');
            sobdgcsj_sj = sobdgcsj_sj.TrimEnd(',');
            string ssql = string.Format("select * from OBD_ZGCSJ where jylsh='{0}'", sjylsh);
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssql);
            if (dt.Rows.Count > 0)
            {
                ssql = string.Format(@"update OBD_ZGCSJ  set 
sobdgcsj_jqmkd='{0}'
,sobdgcsj_fh='{1}'
,sobdgcsj_qycgqxh='{2}'
,sobdgcsj_glkqxs='{3}'
,sobdgcsj_ymkd='{4}'
,sobdgcsj_cs='{5}'
,sobdgcsj_fdjzs='{6}'
,sobdgcsj_jql='{7}'
,sobdgcsj_jqyl='{8}'
,sobdgcsj_scgl='{9}'
,sobdgcsj_zyyl='{10}'
,sobdgcsj_hyl='{11}'
,sobdgcsj_no='{12}'
,sobdgcsj_nsbsl='{13}'
,sobdgcsj_pqwd='{14}'
,sobdgcsj_klbjqyc='{15}'
,sobdgcsj_egrkd='{16}'
,sobdgcsj_rypsyl='{17}'
,sobdgcsj_sj='{18}'
                                                        where jylsh='{19}'",
sobdgcsj_jqmkd
 , sobdgcsj_fh
 , sobdgcsj_qycgqxh
 , sobdgcsj_glkqxs
 , sobdgcsj_ymkd
 , sobdgcsj_cs
 , sobdgcsj_fdjzs
 , sobdgcsj_jql
 , sobdgcsj_jqyl
 , sobdgcsj_scgl
 , sobdgcsj_zyyl
 , sobdgcsj_hyl
 , sobdgcsj_no
 , sobdgcsj_nsbsl
 , sobdgcsj_pqwd
 , sobdgcsj_klbjqyc
 , sobdgcsj_egrkd
 , sobdgcsj_rypsyl
 , sobdgcsj_sj
 , sjylsh);


            }
            else
            {

                ssql = string.Format(@"insert into OBD_ZGCSJ (
                                               jylsh
                                               ,sobdgcsj_jqmkd 
 ,sobdgcsj_fh 
 ,sobdgcsj_qycgqxh 
 ,sobdgcsj_glkqxs 
 ,sobdgcsj_ymkd 
 ,sobdgcsj_cs 
 ,sobdgcsj_fdjzs 
 ,sobdgcsj_jql 
 ,sobdgcsj_jqyl 
 ,sobdgcsj_scgl 
 ,sobdgcsj_zyyl 
 ,sobdgcsj_hyl 
 ,sobdgcsj_no 
 ,sobdgcsj_nsbsl 
 ,sobdgcsj_pqwd 
 ,sobdgcsj_klbjqyc 
 ,sobdgcsj_egrkd 
 ,sobdgcsj_rypsyl 
 ,sobdgcsj_sj ) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}',
                                                '{9}',
                                                '{10}',
                                                '{11}',
                                                '{12}',
                                                '{13}',
                                                '{14}',
                                                '{15}',
                                                '{16}',
                                                '{17}',
                                                '{18}',
                                                '{19}')",
sjylsh
, sobdgcsj_jqmkd
, sobdgcsj_fh
, sobdgcsj_qycgqxh
, sobdgcsj_glkqxs
, sobdgcsj_ymkd
, sobdgcsj_cs
, sobdgcsj_fdjzs
, sobdgcsj_jql
, sobdgcsj_jqyl
, sobdgcsj_scgl
, sobdgcsj_zyyl
, sobdgcsj_hyl
, sobdgcsj_no
, sobdgcsj_nsbsl
, sobdgcsj_pqwd
, sobdgcsj_klbjqyc
, sobdgcsj_egrkd
, sobdgcsj_rypsyl
, sobdgcsj_sj);
            }
            m_mainform.objbass.objdb.InsertDB(ssql);
        }
        xianshiweiqi xswq = new xianshiweiqi();
        private void xianshiHC()
        {
            if (this.time.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiHC);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xswq.textBox1.Text = m_mainform.objfqy.m_iHc.ToString();

            }
        }
        private void xianshiCO()
        {
            if (this.time.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiCO);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xswq.textBox2.Text = m_mainform.objfqy.m_fCo.ToString();

            }
        }
        private void xianshiNO()
        {
            if (this.time.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiNO);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xswq.textBox3.Text = m_mainform.objfqy.m_iNo.ToString();

            }
        }




        public void obdsc()
        {
            gc011 = new 联网通信协议.安车model.GC011();
            string cyds = "";
            string cysx = "";
            string sjxl = "";
            string jqmkd = "";
            string fh = "";
            string qycgqxh = "";
            string glkqxs = "";
            string ymkd = "";
            string cs = "";
            string fdjzs = "";
            string jql = "";
            string jqyl = "";
            string scgl = "";
            string zyyl = "";
            string hyl = "";
            string no = "";
            string nsbsl = "";
            string pqwd = "";
            string klbjqyc = "";
            string egrkd = "";
            string rypsyr = "";
            string jczt = "";

            for (int i = 0; i <= iobd; i++)
            {
                cyds = iobd.ToString();
                cysx = (i + 1).ToString();
                sjxl = sjxl + OBD_sjxl[i] + ",";
                jqmkd = jqmkd + OBD_jqmkd[i] + ",";
                fh = fh + OBD_fh[i] + ",";
                qycgqxh = qycgqxh + OBD_qycgqxh[i] + ",";
                glkqxs = glkqxs + OBD_glkqxs[i] + ",";
                ymkd = ymkd + OBD_ymkd[i] + ",";
                cs = cs + OBD_cs[i] + ",";
                fdjzs = fdjzs + OBD_fdjzs[i] + ",";
                jql = jql + OBD_jql[i] + ",";
                jqyl = jqyl + OBD_jqyl[i] + ",";
                scgl = scgl + OBD_scgl[i] + ",";
                zyyl = zyyl + OBD_zyyl[i] + ",";
                hyl = hyl + OBD_hyl[i] + ",";
                no = no + OBD_no[i] + ",";
                nsbsl = nsbsl + OBD_nsbsl[i] + ",";
                pqwd = pqwd + OBD_pqwd[i] + ",";
                klbjqyc = klbjqyc + OBD_klbjqyc[i] + ",";
                egrkd = egrkd + OBD_egrkd[i] + ",";
                rypsyr = rypsyr + OBD_rypsyl[i] + ",";

            }
            cyds = cyds.Trim(',');
            cysx = cysx.Trim(',');
            sjxl = sjxl.Trim(',');
            jqmkd = jqmkd.Trim(',');
            fh = fh.Trim(',');
            qycgqxh = qycgqxh.Trim(',');
            glkqxs = glkqxs.Trim(',');
            ymkd = ymkd.Trim(',');
            cs = cs.Trim(',');
            fdjzs = fdjzs.Trim(',');
            jql = jql.Trim(',');
            jqyl = jqyl.Trim(',');
            scgl = scgl.Trim(',');
            zyyl = zyyl.Trim(',');
            hyl = hyl.Trim(',');
            no = no.Trim(',');
            nsbsl = nsbsl.Trim(',');
            pqwd = pqwd.Trim(',');
            klbjqyc = klbjqyc.Trim(',');
            egrkd = egrkd.Trim(',');
            rypsyr = rypsyr.Trim(',');
            jczt = jczt.Trim(',');

            gc011.cyds = cyds;
            gc011.cysx = cysx;
            gc011.sjxl = sjxl;
            gc011.jqmkd = jqmkd;
            gc011.fh = fh;
            gc011.qycgqxh = qycgqxh;
            gc011.glkqxs = glkqxs;
            gc011.ymkd = ymkd;
            gc011.cs = cs;
            gc011.fdjzs = fdjzs;
            gc011.jql = jql;
            gc011.jqyl = jqyl;
            gc011.scgl = scgl;
            gc011.zyyl = zyyl;
            gc011.hyl = hyl;
            gc011.no = no;
            gc011.nsbsl = nsbsl;
            gc011.pqwd = pqwd;
            gc011.klbjqyc = klbjqyc;
            gc011.egrkd = egrkd;
            gc011.rypsyl = rypsyr;
            gc011.rypsyr = rypsyr;
            gc011.jczt = jczt;


        }

        private void aGauge1_ValueInRangeChanged(object sender, AGaugeApp.AGauge.ValueInRangeChangedEventArgs e)
        {

        }

        public void sendASMGCSJ(string businessId, string svalue)
        {
            m_mainform.objbass.senddate("HJ07", svalue);
        }

        public void sendASMJG(string businessId)
        {
            JsonData value = new LitJson.JsonData();
            value["InspectionNum"] = businessId;
            value["StationCode"] = m_mainform.stationCode;
            value["SceneCode"] = m_mainform.lineCode;
            value["VLPN"] = m_mainform.VLPN;
            value["VLPNColor"] = m_mainform.VLPNColor;
            value["VIN"] = m_mainform.VIN;
            value["InspectionOperator"] = m_mainform.InspectionOperator;
            value["InspectionDriver"] = m_mainform.InspectionDriver;
            value["ICheck"] = m_mainform.InspectionOperator;
            value["CheckTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            value["Temperature"] = fwendu.ToString("0.0");
            value["Pressure"] = fdaqiya.ToString("0.0");
            value["Humidity"] = fshidu.ToString("0.0");
            value["IUTID"] = string.Format("{0}{1}{2}", m_mainform.stationCode, m_mainform.lineCode, m_mainform.IUTID);
            value["IUIDATE"] = DateTime.Now.ToString("yyyy-MM-dd");
            value["DetectStartTime"] = timeStart;
            value["DetectEndTime"] = timeEnd;
            value["VDCT"] = bgood ? "1" : "0";
            value["ASMType"] = ASMType;
            value["EACR"] = "";//问题
            value["HCEL5025"] = m_mainform.HCEL5025;
            value["HCER5025"] = iHC25;
            value["HCED5025"] = iHC25 > m_mainform.HCEL5025 ? "0" : "1";
            value["HCEL2540"] = m_mainform.HCEL2540;
            value["HCER2540"] = iHC40;
            value["HCED2540"] = iHC40 > m_mainform.HCEL2540 ? "0" : "1";
            value["COEL5025"] = m_mainform.COEL5025;
            value["COER5025"] = fCO25;
            value["COED5025"] = fCO25 > m_mainform.COEL5025 ? "0" : "1";
            value["COEL2540"] = m_mainform.COEL2540;
            value["COER2540"] = fCO40;
            value["COED2540"] = fCO40 > m_mainform.COEL2540 ? "0" : "1";
            value["NOEL5025"] = m_mainform.NOEL5025;
            value["NOER5025"] = iNO25;
            value["NOED5025"] = iNO25 > m_mainform.NOEL5025 ? "0" : "1";
            value["NOEL2540"] = m_mainform.NOEL2540;
            value["NOER2540"] = iNO40;
            value["NOED2540"] = iNO40 > m_mainform.NOEL2540 ? "0" : "1";
            string svalue = value.ToJson();
            m_mainform.objbass.senddate("HJ08", svalue);
        }
        private void xianshicojiaco2()
        {
            if (this.txtcoaddco2.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshicojiaco2);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtcoaddco2.Text = (m_mainform.objfqy.m_fCo + m_mainform.objfqy.m_fCo2).ToString("0.00");

            }
        }

        private void xianshisp()
        {
            if (this.txtsp.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshisp);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txtsp.Text = m_fspeed.ToString("0.0");

            }
        }
        bool bydhh = false;

        private void 该车为油电混合ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bydhh = true;
        }

        private void TESTASM_Load(object sender, EventArgs e)
        {
            bobdhg = false;
            控制流程.flowcrtl.iquanjuzhuangtai = 1;
        }

        private void TESTASM_FormClosing(object sender, FormClosingEventArgs e)
        {

            控制流程.flowcrtl.iquanjuzhuangtai = 0;
            m_mainform.DAC.PutVol(0);
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        float fywrg = 0;
        bool byw = false;
        private void 油温人工确认ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql = string.Format(@"
CREATE TABLE [dbo].[ywrgqr](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[jylsh] [varchar](50) NULL,
	[hphm] [varchar](50) NULL,
	[yuanyin] [varchar](500) NULL,
	[czy] [varchar](50) NULL,
	[yw] [real] NULL,
	[lrtime] [datetime] NULL
) ON [PRIMARY]");
            try
            {
                m_mainform.objbass.objdb.InsertDB(sql);
            }
            catch (Exception) { }

            尾气流程仪表.youwenrengong f = new 尾气流程仪表.youwenrengong();
            f.slsh = businessId;
            f.shphm = hphm.Text;
            f.scaozuoyuan = m_mainform.InspectionOperator;
            if (f.ShowDialog() == DialogResult.OK)
            {
                byw = true;
                fywrg = f.fyw;               
                sql = string.Format("insert into ywrgqr (jylsh,hphm,yuanyin,czy,yw,lrtime) values ('{0}','{1}','{2}','{3}',{4},'{5}')",
                    f.slsh, f.shphm, f.syuanyin, f.scaozuoyuan, f.fyw, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                m_mainform.objbass.objdb.InsertDB(sql);
            }
        }

        private void aGauge13_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void form_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                oBD上传ToolStripMenuItem.Visible = true;
                跳过自检ToolStripMenuItem.Visible = true;
            }

        }

        private void form_KeyUp(object sender, KeyEventArgs e)
        {
            oBD上传ToolStripMenuItem.Visible = false;
            跳过自检ToolStripMenuItem.Visible = false;
        }

        private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)
        {
            oBD上传ToolStripMenuItem.Visible = false;
            跳过自检ToolStripMenuItem.Visible = false;
        }
        bool bobdhg = false;
        private void oBD上传ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bobdhg = true;
        }

        private void 跳过自检ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bzijian = false;
        }
    }
}
